Re: [R] Fill blank column in the data frame

2012-02-13 Thread alend
The solution is easy!

lapply(X, function(x){replace(x, x == 0, newword)})

--
View this message in context: 
http://r.789695.n4.nabble.com/Fill-blank-column-in-the-data-frame-tp4386328p4386361.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] Fill blank column in the data frame

2012-02-13 Thread alend
Hi,

  I have read a data frame by using read.table and set fill=TRUE, so the
missing columns  are filled with blank. How can I fill them with a word like
NA?



--
View this message in context: 
http://r.789695.n4.nabble.com/Fill-blank-column-in-the-data-frame-tp4386328p4386328.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] Writing R-scripts

2012-02-13 Thread ilai
It seems all you are doing in the if statements is defining functions.
You need to actually "apply" them to some arguments, then you can pass
results.
i.e.
f<- function(x,type,...){
a<- function(...){   2* x }
b<- function(...) {  x^2 }
if(type==1){ ret<- a(x) }
if(type==2){ ret<- b(x) }
ret
}

You may also want to see ?switch or ?local

Cheers

On Mon, Feb 13, 2012 at 2:59 PM, Cem Girit  wrote:
> Hello,
>
>        This is my first attempt to write a script in R. The program below
> is intended to do some parametric tests on group data. There are subroutines
> for each type of test. The call to the "parametric.tests", routine sets the
> argument "testtype" for the test to be used. How can I transfer the
> calculated values (in "result" below) in each routine to the calling
> parametric.tests routine?
>
> Cem
>
> 
>
>
> ## testtype : 1: Duncan
> ##                     2: Dunnett
> ## resp:  response variable, must be numeric and vector
> ## group: group id for resp, numeric or character
> ## alpha: CL 0.05 or 0.01
> ## vehicle: Control group name for Dunnett
>
> parametric.tests<-function(testtype, resp, group, vehicle, alpha)
> {
> if (testtype==1){
>
> ## resp:  response variable, must be numeric and vector
> ## group: group id for resp, numeric or character
> ## alpha: CL 0.05 or 0.01
>
>  duncan.test <- function (resp, group, alpha) {
>
> .
>
> result <- data.frame(label=label, estimate=Estimate, alpha=alpha,
> lower=Lower, upper=Upper, p.value=pval, significance=sig)
> return(result)
> }
> }
>
> else if (testtype==2){
>
>
> dunnett.test <- function(resp, group, vehicle, alpha)
> {
>
> .
>
>  result <- data.frame(label=label, estimate=Estimate, alpha=alpha,
> lower=Lower, upper=Upper, p.value=pval, significance=sig)
>  return(result)
> }

> }

> }
>
> Cem
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] help with matrix column cleaning

2012-02-13 Thread David Winsemius


On Feb 14, 2012, at 12:46 AM, Vijayan Padmanabhan wrote:


Dear R Group
I have a matrix object in R, where i want to retain only those columns
which have each row from a different group..

see the example below..
team1<-c("a1","a2","b1","b2","b3","c1","c2")

teams<-combn(team1, 3)

I want a function which will delete all columns in the teams matrix  
that

have more than 1 row having same letter starts..

For instance in the example object teams,  I want to retain column
8,11,12,13,14,18,19,21,22,23,24 .


This will give you a logical vector which you can use with "[" in the  
column position to select those columns:



 apply(teams, 2, function(x) length( unique(substr(x, 1,1))) ==3 )

 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE   
TRUE  TRUE
[13]  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE   
TRUE  TRUE

[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE


I am looking at doing this in larger matrix objects using a function
preferrably that i can apply to the matrix object to check for the
beginning letter of each cell from each row and delete columns that  
have

more than one row having the same start letter.

Thanks for your help.
Regards
Vijayan Padmanabhan




--
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] Subset a datafram according to time

2012-02-13 Thread NickNz125
Its just made up for the time being, they are just made up values to explain
what i want to be able to do. This data in same format as my actual data
set. Cheers
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Subset-a-datafram-according-to-time-tp4372293p4386197.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] Selection by ordered factors

2012-02-13 Thread johnmark
What I want to do is create a data.frame column from ranges of dates (e.g.
annual quarters) as an ordered factor, then use this column to select by
ranges of the factor (e.g. all quarters in 2009).  

The factors capture the date ranges, instead of having to write elaborate
code to do range selection.

How I do this is with a function "which.quarter" that returns the date-range
ordered factor corresponding to a date, so I can do things like 

/my.data[my.data$date.range.factor >= which.quarter(the.start.date),]
/
The problem is in creating the date-range factor column.  Applying
"which.quarter()" to the date column returns a factor that is no-longer
ordered. The cheat I used to fix this is to coerce the column class back to
ordered factor, with this code:

/### Creating a quarters factor column from a date column
##  !! Why does unlist return a vector of factors, and not ordered factors?  
quarters <- function(date.column) {
qtr.column <- unlist(sapply(date.column, which.quarter ))
class(qtr.column) <- c("ordered", "factor" )
qtr.column
}/

Question:  
1) Is there a clean way to preserve the factor ordering thru the 
"unlist(sapply(..."?
2) Is there an easier way to manipulate ranges using ordered factors?

Appreciatively - john mark agosta


--
View this message in context: 
http://r.789695.n4.nabble.com/Selection-by-ordered-factors-tp4386203p4386203.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] different way for a for loop for several columns?

2012-02-13 Thread Rui Barradas
Hello,

> 
> I use a for loop to take into account the years.
> Then, I want to do this as well for the other objects and I use again
> another loop around it.
> The script works well, but it takes a lot of time. 
> 

Look at the first line in the inner loop:

> for (l in 1:3)
> {
> for (y in 1980:1983)
> {
> test.2<-ifelse(test[,l]>1,1,0) 
>  [... etc ...]

It doesn't depend on 'y', could be put outside that loop. This alone would
save time.
What also saves time is to see that you're choosing values 1 and 0 depending
on the 'ifelse' condition.
To simply do

test.2 <- test[, l] > 1# Use TRUE = 1 and FALSE = 0

makes it 20 times faster (!) (Tested with a much larger 'test'  data.frame.)

>
> Does somebody knows a way to do this? I was thinking about some kind of
> form of apply, ...

With no loops, only *apply:

# After creating the data frames save a copy of the original 'test.1'
# (This line should be before the loops)
test.1b <- test.1

# Now, after the loops and after attributing names to the result, try the
following.

# Could this become 'unique(Year$Date)' ?
y <- 1980:1983

# This is a matrix, not vector by vector like above. It's the matrix 'xx' in
the nested 'apply'
test.2b <- test > 1

# This is the index 'jj' into 'xx'
test.3b <- sapply(y, function(yy) which(Year$Date == yy))

Length <- t(apply(test.3b, 2, function(jj)
apply(test.2b, 2, function(xx) sum(xx[jj]

# Maybe we don't need to save 'test.1b', if it's possible to cbind(y,
Length)
test.1b <- cbind(test.1b, Length)

names(test.1b) <- c("year", "C", "B", "F")

all.equal(test.1, test.1b)

I bet this is faster.

A final note, it's not a very good idea to use R's objects as variables
names .
For instance, 'length'. Prefer 'Length', it's not a object/function.

Hope this helps,

Rui Barradas



--
View this message in context: 
http://r.789695.n4.nabble.com/different-way-for-a-for-loop-for-several-columns-tp4385705p4385992.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] Getting codebook data into R

2012-02-13 Thread Chris Stubben
Just to follow up on Dan's code - once you have a data.frame listing column
positions, then it's just a couple steps to download the file...

x <- data.frame(name=c('caseid', 'nbrnaliv', 'babysex',
'birthwgt_lb','birthwgt_oz','prglength',
'outcome', 'birthord',  'agepreg',  'finalwgt'),
begin = c(1, 22, 56, 57, 59, 275, 277, 278, 284, 423),
end =  c(12, 22, 56, 58, 60, 276, 277, 279, 287, 440)
)


x$width <- x$end - x$begin + 1
x$skip <-  (-c(x$begin[-1]-x$end[-nrow(x)]-1,0))

widths <- c(t(x[,4:5]))
widths <- widths[widths!=0]

ftp<-
"ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NSFG/2002FemPreg.dat";
# drop the n=10 option to get all lines
y<- read.fwf(ftp, widths, n=10)
names(y) <- x$name
y
   caseid nbrnaliv babysex birthwgt_lb birthwgt_oz prglength outcome
birthord agepreg  finalwgt
1   11   1   8  1339   1   
13316  6448.271
2   11   2   7  1439   1   
23925  6448.271
3   23   1   9   239   1   
11433 12999.542
4   21   2   7   039   1   
21783 12999.542
5   21   2   6   339   1   
31833 12999.542
6   61   1   8   938   1   
12700  8874.441
7   61   2   9   940   1   
22883  8874.441
8   61   2   8   642   1   
33016  8874.441
9   71   1   7   939   1   
12808  6911.880
10  71   2   6  1035   1   
23233  6911.880


Chris Stubben




Daniel Nordlund-4 wrote
> 
>> -Original Message-
> 
>> I've been trying to get some data from the National Survey for Family
>> Growth
>> into R - however, the data is in a .dat file and the data I need doesn't
>> have any spaces or commas separating fields - rather you have to look
>> into
>> the codebook and what number of digits along the line the data you need
>> is.
>> The data I want are the following, where 1,12,int means that the data I'm
>> interested starts in column 1 and finishes in column 12 and is an
>> integer.
>> 
>> ('caseid', 1, 12, int),
>>  ('nbrnaliv', 22, 22, int),
>> ('babysex', 56, 56, int),
>> ('birthwgt_lb', 57, 58, int),
>> ('birthwgt_oz', 59, 60, int),
>> ('prglength', 275, 276, int),
>> ('outcome', 277, 277, int),
>> ('birthord', 278, 279, int),
>> ('agepreg', 284, 287, int),
>> ('finalwgt', 423, 440, float)
>> 
>> How can I do this using R? I've written a python programme which
>> basically
>> does it but it'd be nicer if I could skip the Python bit and just do it
>> using R. Cheers for any help.
>> 
> 
> 
> Dan
> 
> 
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Getting-codebook-data-into-R-tp4374331p4386135.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] help with matrix column cleaning

2012-02-13 Thread Vijayan Padmanabhan
Dear R Group
I have a matrix object in R, where i want to retain only those columns 
which have each row from a different group..

see the example below..
team1<-c("a1","a2","b1","b2","b3","c1","c2")

teams<-combn(team1, 3)

I want a function which will delete all columns in the teams matrix that 
have more than 1 row having same letter starts..

For instance in the example object teams,  I want to retain column 
8,11,12,13,14,18,19,21,22,23,24 .
I am looking at doing this in larger matrix objects using a function 
preferrably that i can apply to the matrix object to check for the 
beginning letter of each cell from each row and delete columns that have 
more than one row having the same start letter.

Thanks for your help.
Regards
Vijayan Padmanabhan


"What is expressed without proof can be denied without proof" - Euclide. 

Please visit us at www.itcportal.com
**
This Communication is for the exclusive use of the intended recipient (s) and 
shall
not attach any liability on the originator or ITC Ltd./its Subsidiaries/its 
Group 
Companies. If you are the addressee, the contents of this email are intended 
for your use only and it shall not be forwarded to any third party, without 
first obtaining written authorisation from the originator or ITC Ltd./its 
Subsidiaries/its Group Companies. It may contain information which is 
confidential and legally privileged and the same shall not be used or dealt 
with by any third party in any manner whatsoever without the specific consent 
of ITC Ltd./its Subsidiaries/its Group Companies.
[[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] sequencing environments

2012-02-13 Thread Ben quant
Hello,

I can get at environments if I know their names, but what if want to look
at what environments currently exist at some point in a script? In other
words, if I don't know what environments exist and I don't know their
sequence/hierarchy, how do I display a visual representation of the
environments and how they relate to one another?

I'm looking at getting away from the package R.oo and using R in normal
state, but I need a way to "check in on" the status and organization of my
environments.

I've done considerable research on R's environments, but its a challenging
thing to google and come up with meaningful results.

Thanks,

Ben

[[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] Counting the loop-round of a "for"-loop

2012-02-13 Thread 538280
Consider using sapply instead of a for loop, if the code in the sapply
call returns a vector, and every vector is the same length, then
sapply will automatically form it into a matrix for you.

On Sun, Feb 12, 2012 at 12:30 PM, jolo999  wrote:
> It seems to work. Simple and effective!
>
> Thanks!
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Counting-the-loop-round-of-a-for-loop-tp4381319p4381780.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.



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

2012-02-13 Thread zheng wei
Dear Petr,
 
Your codes are so beautiful!
 
When I have a matrix s, with each column represents a sequence. I want to 
recover all equivalent sequences from the sequences/columns in s. I used this 
command
 
do.call(cbind,apply(s,2,function(x) getEquivalent(x,tt)))
 
This did a good job when ncol(s) >1, but when ncol(s)=1, there is an error. 
 
How to getter a better coding which could deal with either the case of ncol(s) 
>1 or ncol(s)=1 by itself?
 
Thanks a lot,
Wei
 



From: Petr Savicky 
To: r-help@r-project.org 
Sent: Monday, February 13, 2012 5:38 PM
Subject: Re: [R] non-isomorphic sequences

On Mon, Feb 13, 2012 at 02:04:51PM -0800, zheng wei wrote:
> Dear Petr,
>  
> This is fantastic!
>  
> I have one more question, when p=4, tt=4. We have 15 non-isomorphic sequences 
> as you have generated. Among these 15, I selected 2 sequences. How do I 
> recover all the members of the equivalent classes corresponding to these 2 
> sequences? For example, corresponding to the sequence of , I would like 
> to recover ,,, from this sequence.

Dear Wei:

Try the following.

  getEquivalent <- function(a, tt)
  {
      b <- as.matrix(rev(expand.grid(rep(list(1:tt), times=max(a)
      ok <- apply(b, 1, function(x) length(unique(x))) == ncol(b)
      b <- b[ok, , drop=FALSE]
      dimnames(b) <- NULL
      t(apply(b, 1, function(x) x[a]))
  }

  getEquivalent(c(1, 1, 1, 1), 4)

      [,1] [,2] [,3] [,4]
  [1,]    1    1    1    1
  [2,]    2    2    2    2
  [3,]    3    3    3    3
  [4,]    4    4    4    4

  getEquivalent(c(1, 1, 1, 2), 4)

        [,1] [,2] [,3] [,4]
  [1,]    1    1    1    2
  [2,]    1    1    1    3
  [3,]    1    1    1    4
  [4,]    2    2    2    1
  [5,]    2    2    2    3
  [6,]    2    2    2    4
  [7,]    3    3    3    1
  [8,]    3    3    3    2
  [9,]    3    3    3    4
  [10,]    4    4    4    1
  [11,]    4    4    4    2
  [12,]    4    4    4    3

Hope this helps.

Petr.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] only 0s may be mixed with negative subscripts

2012-02-13 Thread Rui Barradas
Hello,

>
> I'm trying to get a piecewise sum of every n rows in a given column in
> this data set. 
>

Is this it?

# Result as a matrix, each column a piecewise cumsum
mat <- sapply(which(sens2$rownumber %% 2 == 0),
function(row) cumsum(c(sens2[row-1, 3], sens2[row, 3])))

# The same but c() makes it a vector
vec <- c(sapply(which(sens2$rownumber %% 2 == 0),
function(row) cumsum(c(sens2[row-1, "X"], sens2[row, "X"]

# See the results
data.frame(sens2, CumSum=vec)

If this is what you want, return to your original 'sapply' instruction and
see that
you were passing entire rows to 'function(row)', not just row numbers.
It was too complicated.
(If it's not, sorry, but I missed the point.)

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/only-0s-may-be-mixed-with-negative-subscripts-tp4384887p4385803.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] mgcv: increasing basis dimension

2012-02-13 Thread Greg Dropkin
hi

Using a ts or tprs basis, I expected gcv to decrease when increasing the
basis dimension, as I thought this would minimise gcv over a larger
subspace. But gcv increased. Here's an example. thanks for any comments.

greg

#simulate some data
set.seed(0)
x1<-runif(500)
x2<-rnorm(500)
x3<-rpois(500,3)
d<-runif(500)
linp<--1+x1+0.5*x2+0.3*exp(-2*d)*sin(10*d)*x3
y<-rpois(500,exp(linp))
sum(y)

library(mgcv)
#basis dimension k=5
m1<-gam(y~x1+x2+te(d,bs="ts")+te(x3,bs="ts")+te(d,x3,bs="ts"),family="poisson")

#basis dimension k=10
m2<-gam(y~x1+x2+te(d,bs="ts",k=10)+te(x3,bs="ts",k=10)+te(d,x3,bs="ts",k=10),family="poisson")

#gcv increased
m1$gcv
m2$gcv

summary(m1)
summary(m2)

gam.check(m1)
gam.check(m2)


#is this due to bs="ts"?

#basis dimension k=5
m1tp<-gam(y~x1+x2+te(d,bs="tp")+te(x3,bs="tp")+te(d,x3,bs="tp"),family="poisson")

#basis dimension k=10
m2tp<-gam(y~x1+x2+te(d,bs="tp",k=10)+te(x3,bs="tp",k=10)+te(d,x3,bs="tp",k=10),family="poisson")

m1tp$gcv
m2tp$gcv

#no

summary(m1tp)
summary(m2tp)

gam.check(m1tp)
gam.check(m2tp)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] comment lines sometimes removed from a function on exit from internal R editor

2012-02-13 Thread Cleridy Lennert
Dear All -
The problem: comment lines in an R function (lines beginning with # ) are 
*sometimes* removed on leaving the R default editor (same with notepad).
I'm working on a Windows machine with R version 2.14.1.
An example is below. Couldn't find anything that seemed to relate to this in 
the Changelog. I don't recall encountering this behavior with previous versions 
of R. Any suggestions on how to preserve the comment lines would be greatly 
appreciated. Many apologies if this is a stupid question. Cleridy


## this function has comments at the top:

> mapsp.sqrtcpd.f

function (input.frm, cpd.numerator, cpd.denominator, basis.dim,

  npts, nyrs.unq, prop.ctch)

{

# here are some comments

# and more

#

  year.min<- 1975

..



## copy function to a dummy function:

> tmp.f<-mapsp.sqrtcpd.f



## now edit it with fix and remove a ) so that it complains:

>  fix(tmp.f)

Error in edit(name, file, title, editor) :

unexpected symbol occurred on line 15 use a command like

x<- edit()

to recover



## and now recover it and add back in the ) that had been removed :

> tmp.f<-edit()



## and look to see what happened... no comments at the top anymore..

> tmp.f

function (input.frm, cpd.numerator, cpd.denominator, basis.dim,

  npts, nyrs.unq, prop.ctch)

{

  year.min<- 1975

..


[[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] different way for a for loop for several columns?

2012-02-13 Thread Nerak
Hi,
I have a question about repeating something for several columns.  I
calculated a lot of values for different objects. The values are normally
calculated step-wise for every day for each object. With this obtained data
frame, I make further calculations. Here I have to calculate some things and
I have to take into account the years because I want a number for each year.
I do these first for one object. I use a for loop to take into account the
years. Then, I want to do this as well for the other objects and I use again
another loop around it. The script works well, but it takes a lot of time.
Because of that, I want to see if there is another way to do this.
I made a reproducible script that has some characteristics of my script, but
that is simplified a lot. Instead of daily values, the reproducible script
has only 4 datapoints a year and instead if more than 30 years, here are
only 4 years used. As well, instead of more than 100 objects, the example
has only 3 (C,B,F).  Normally I don’t obtain the dataframe test in this way,
it’s just to create a reproducible script. Normally, the script between the
for (y in 1980:1983) { } loop is also much more extensive, “ 
[which(Year$Date== y)]“ is used several  times an some small loops are
included. 

Reproducible script:
Date<-c(1980,1980,1980,1980,1981,1981,1981,1981,1982,1982,1982,1982,1983,1983,1983,1983)
C<-c(0,0,0,0,5,2,0,0,0,15,12,10,6,0,0,0)
B<-c(0,0,0,0,9,6,2,0,0,24,20,16,2,0,0,0)
F<-c(0,0,0,0,6,5,1,0,0,18,16,12,10,5,1,0)


test<-data.frame(C,B,F)
Year<-data.frame(Date)
test.1<-data.frame(c(1980:1983))
test.4<-data.frame(c(1:4))

for (l in 1:3)
{
for (y in 1980:1983)
{
test.2<-ifelse(test[,l]>1,1,0)
test.3<-test.2[which(Year$Date== y)]
test.4$length[y-Year[1,]+1]<-length(which(test.3>0))
}
test.1<-cbind(test.1, test.4$length)
}
names(test.1)<-c("year","C","B","F")

test.1


You can see that it will take a lot of time for more objects and years. A
problem is that the for (y in 1980:1983) { } takes a lot of time because “
[which(Year$Date== y)] ” is used several times and it takes a lot of time to
search through all the rows. And then, all of this has to be repeated
several times for the different objects.
But actually, it are totally the same calculations that have to be made for
all the objects. Only the input data are different. (calculations are made
with the values of a corresponding columns of data frame test). I thought it
could be faster to calculate each step of the inner loop (for (y in
1980:1983) at the same time for each object . So for example: now,
test.2<-ifelse(test[,l]>1,1,0) is first calculated for year 1980 for object
1, than for year 1981 for object 1 and so on for all the years, this is all
repeated for the different object. I’m looking for a way to calculate
test.2<-ifelse(test[,l]>1,1,0) first for all the objects for year 1980, ten
for all the objects for year 1981 and so on. 

Does somebody knows a way to do this? I was thinking about some kind of form
of apply, but it’s not that I have created a function that has to be applied
on a whole column, calculations are done for the different rows…

Many thanks for your help!
Kind regards,
Nerak


--
View this message in context: 
http://r.789695.n4.nabble.com/different-way-for-a-for-loop-for-several-columns-tp4385705p4385705.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] only 0s may be mixed with negative subscripts

2012-02-13 Thread ilai
Like this ? sum every batch of n rows?

N <- 2
t(kronecker(diag(nrow(sens2)/N),rep(1,N))) %*% as.matrix(sens2)

   Time Y X rownumber
[1,] 2657130134 0.3236854 0.1080725 3
[2,] 2657130134 0.4621816 0.1198302 7
[3,] 2657130134 0.4341804 0.106958311

Check rownumber column: 1+2 = 3, 3+4 = 7, 5+6=11 ...

Or sum every 3 rows:
 N <- 3
 t(kronecker(diag(nrow(sens2)/N),rep(1,N))) %*% as.matrix(sens2 )
   Time Y X rownumber
[1,] 3985695201 0.5646581 0.1693338 6
[2,] 3985695202 0.6553893 0.165527215

Hope this helps (more...).

On Mon, Feb 13, 2012 at 4:04 PM, Hasan Diwan  wrote:
> On 13 February 2012 14:46, ilai  wrote:
>> The function you posted runs without error (on these 6 lines), but
>> does not return anything that looks remotely like a sum, or cumsum of
>> anything. Can you clarify what you are trying to do? I assume by "sum
>> of every other row" you don't mean summing Time, X and Y for rows
>> 1,3,5,..., ?
>
> I'm trying to get a piecewise sum of every n rows in a given column in
> this data set.
>> For the sum of sens2[c(1,3,5,...),] for every column (assuming no NA's
>> in the data) you could
>
> I do format checking well before getting to this stage in the analysis.
>>
>>  (1:nrow(sens2) %% 2) %*% as.matrix(sens2)
>
> That does not do what I want... Again, what it should return is a list
> of the sum of the current and preceding row.
> --
> Sent from my mobile device
> Envoyait de mon portable
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] survey package svystat objects from predict()

2012-02-13 Thread Thomas Lumley
On Tue, Feb 14, 2012 at 11:45 AM, Kieran Healy  wrote:
> Hello,
>
> I'm running R 2.14.1 on OS X (x86_64-apple-darwin9.8.0/x86_64 (64-bit)), with 
> version 3.28 of Thomas Lumley's survey package. I was using predict() from 
> svyglm(). E.g.:
>
> data(api)
> dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
> out <- svyglm(sch.wide~ell+mobility, design=dstrat,
>        family=quasibinomial())
> pred.df <- expand.grid(ell=c(20,50,80), mobility=20)
> out.pred <- predict(out, pred.df)
>
> From the console out.pred looks like this:
>
>> class(out.pred)
> [1] "svystat"
>
>> print(out.pred) # or just 'out.pred'
>    link     SE
> 1 1.8504 0.2414
> 2 1.6814 0.3033
> 3 1.5124 0.5197
>
> From here I wanted to conveniently access the predicted values and SEs. I 
> thought that I might be able to do this using either ftable() or 
> as.data.frame(), as methods for these exist for the objects of class 
> "svystat". But while the predicted values come through fine, the SE only gets 
> calculated for the first element and is then repeated:
>
>> ftable(out.pred)
>          A         B
> 1 1.8504120 0.2413889
> 2 1.6814293 0.2413889
> 3 1.5124466 0.2413889
>
>> as.data.frame(out.pred)
>      link        SE
> 1 1.850412 0.2413889
> 2 1.681429 0.2413889
> 3 1.512447 0.2413889
>
> I think what's happening is that as.data.frame.svystat() method in the survey 
> package ends up calling the wrong function to calculate the standard errors.  
> From the survey package:
>
> as.data.frame.svystat<-function(x,...){
>  rval<-data.frame(statistic=coef(x),SE=SE(x))
>  names(rval)[1]<-attr(x,"statistic")
>  if (!is.null(attr(x,"deff")))
>    rval<-cbind(rval,deff=deff(x))
>  rval
> }
>
> The relevant SE method seems to be:
>
> SE.svrepstat<-function(object,...){
>  if (is.list(object)){
>    object<-object[[1]]
>  }
>  vv<-as.matrix(attr(object,"var"))
>  if (!is.null(dim(object)) && length(object)==length(vv))
>    sqrt(vv)
>  else
>    sqrt(diag(vv))
> }

Mostly correct, but the relevant SE method is actually SE.default
survey:::SE.default
function (object, ...)
{
sqrt(diag(vcov(object, ...)))
}

It can't be SE.svrepstat, because the class is wrong.

If you define
SE.svystat<-function(object,...){
   v<-vcov(object)
   if (!is.matrix(v) || NCOL(v)==1) sqrt(v) else sqrt(diag(v))
 }

it should work.

-thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] If (x > 0)

2012-02-13 Thread Henrik Bengtsson
Try adding --vanilla when calling R, e.g.

R --vanilla --no-save --args 5 < test1.R

because I think you're picking up and previously stored session.
You'll most likely will find that "res <- conditional1(x)" will give
an error saying 'conditional1' is not defined; you need to define the
function before using it.

My $.02

/H

On Mon, Feb 13, 2012 at 1:59 PM, Schmidt, Michael
 wrote:
> Hi,
> I am new to R. I was trying to get a very simple program to run. Take one 
> number from the command line. If the number < 0 return -1. If number > 0 
> return 1 and if the number == 0 return 0. The code is in a file called test1.R
>
>
> The code:
>
> #useage: R --no-save --args 5 < test1.R
> args = (commandArgs(TRUE))
> x = as.numeric(args[1])
> print(x)
>
> res <- conditional1(x)
> cat("result= ",res,"\n")
>
> conditional1 <- function(x){
>        result <- 0
>        if (x > 0) {
>                result <- 1
>        } else if (x < 0) {
>                result <- -1
>        }
>        return(result)
> }
>
>
> The output:
>>R --no-save --slave --args 1 < test1.R
> [1] 1
> result=  1
>>R --no-save --slave --args -1 < test1.R
> [1] -1
> result=  -1
>>] R --no-save --slave --args 0 < test1.R
> [1] 0
> result=  -1
>
>
> The problem:
> For arguments 1 and -1 it works as intended. For 0 (zero) it does not. If the 
> 0 value is passed into the function named "conditional1"  I would expect both 
> if-statements to evaluate to false and 0 being return. From what I can tell 
> (0 < 0) evaluates to true since -1 is returned. Hm...
> What is going on? What am I doing wrong? Why is this happening? I am baffled!
> Any help would be appreciated.
> Thanks
> Mike
>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] hexplom question(s)

2012-02-13 Thread Debs Majumdar
Hi,

   I am trying to use the --hexplom-- function to draw a scatterplot matrix.

The following works for me: hexplom(~file[,1:4], xbins=15,  xlab="")

However, I want to make some changes to the graph:

a) I only want to print/draw only one-half of the plot. Is there anyway to get 
rid of the plots in the lower triangular matrix?

b) Is there anyway, I can overwrite the xlabels?

c) Not very important, but the variables start from the bottom and goes up. 
E.g. I am plotting 4 variables ans I have a 4x4 matrix for the plot. Is there 
anyway I can reverse the diagonals? i.e I would like to list the variables and 
axes on 1x1, 2x2, 3x3 and 4x4 rather than the default where it lists the first 
variable on 4x1 follwed by 3x2, 2x3 and 1x4?


Thanks,

-Joey


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] If (x > 0)

2012-02-13 Thread jim holtman
Seems to work fine for me:

> conditional1 <- function(x){
+result <- 0
+if (x > 0) {
+result <- 1
+} else if (x < 0) {
+result <- -1
+}
+return(result)
+ }
> conditional1(-1)
[1] -1
> conditional1(1)
[1] 1
> conditional1(0)
[1] 0
>


On Mon, Feb 13, 2012 at 4:59 PM, Schmidt, Michael
 wrote:
> Hi,
> I am new to R. I was trying to get a very simple program to run. Take one 
> number from the command line. If the number < 0 return -1. If number > 0 
> return 1 and if the number == 0 return 0. The code is in a file called test1.R
>
>
> The code:
>
> #useage: R --no-save --args 5 < test1.R
> args = (commandArgs(TRUE))
> x = as.numeric(args[1])
> print(x)
>
> res <- conditional1(x)
> cat("result= ",res,"\n")
>
> conditional1 <- function(x){
>        result <- 0
>        if (x > 0) {
>                result <- 1
>        } else if (x < 0) {
>                result <- -1
>        }
>        return(result)
> }
>
>
> The output:
>>R --no-save --slave --args 1 < test1.R
> [1] 1
> result=  1
>>R --no-save --slave --args -1 < test1.R
> [1] -1
> result=  -1
>>] R --no-save --slave --args 0 < test1.R
> [1] 0
> result=  -1
>
>
> The problem:
> For arguments 1 and -1 it works as intended. For 0 (zero) it does not. If the 
> 0 value is passed into the function named "conditional1"  I would expect both 
> if-statements to evaluate to false and 0 being return. From what I can tell 
> (0 < 0) evaluates to true since -1 is returned. Hm...
> What is going on? What am I doing wrong? Why is this happening? I am baffled!
> Any help would be appreciated.
> Thanks
> Mike
>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] Discrete Event Simulation problem

2012-02-13 Thread Norm Matloff

Unfortunately, I don't have time to read your code, but if it is any
help, I have general discrete event simulation code as an example in my
book.  I've posted the code at

http://heather.cs.ucdavis.edu/DES.R

Norm Matloff

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] matrix subsetting

2012-02-13 Thread Duncan Murdoch

On 12-02-13 5:46 PM, R. Michael Weylandt  wrote:

which(x>0)

or

which(x>0, arr.ind=TRUE)

depending on your application.


Or even x>0 if you want a matrix of TRUE/FALSE values.  You can use 
x[x>0] to get the values, but they won't be in matrix form.


Duncan Murdoch




Michael

On Feb 13, 2012, at 5:38 PM, Sam Steingold  wrote:


if I have a vector, I can find the indexes which satisfy a condition:
x<- rnorm(10)
[1]  0.4751132 -0.5442322 -0.1979854 -0.2455521  0.8349336 -0.4283345
[7]  0.6108130  2.0576160  1.1251716 -1.3933637
x[x>0]
[1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716
(1:10)[x>0]
[1] 1 5 7 8 9

how about a matrix?

   0G  0Q  2O   35   37   3A
0G NA 0.008226002 0.005631718 0.0002625585 0.0010673235 0.0045310915
0Q NA  NA 0.003714951 0.0002007877 0.0016983426 0.0011083925
2O NA  NA  NA 0.0024233691 0.0069849678 0.0024510792
35 NA  NA  NA   NA 0.0006499707 0.0008420414
37 NA  NA  NA   NA   NA 0.0005448872
3A NA  NA  NA   NA   NA   NA
3B NA  NA  NA   NA   NA   NA
3G NA  NA  NA   NA   NA   NA
3H NA  NA  NA   NA   NA   NA
3I NA  NA  NA   NA   NA   NA
 3B   3G   3H  3I
0G 0.0007254316 0.0093954826 3.420231e-04 0.003974556
0Q 0.0013883606 0.0019778247 3.609791e-05 0.001552725
2O 0.0027340806 0.0082790646 2.561862e-03 0.012297821
35 0.0006025767 0.0004534397 1.053946e-03 0.001681780
37 0.0005501974 0.0021137871 1.733880e-03 0.003712675
3A 0.0008969849 0.0043855527 2.786194e-06 0.002492954
3B   NA 0.0019791290 8.301787e-04 0.002816774
3G   NA   NA 3.181892e-07 0.010608717
3H   NA   NA   NA 0.001066141
3I   NA   NA   NA  NA

how do I find the cells whose values are, e.g.,>  0.01 ??


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
On 13 February 2012 14:46, ilai  wrote:
> The function you posted runs without error (on these 6 lines), but
> does not return anything that looks remotely like a sum, or cumsum of
> anything. Can you clarify what you are trying to do? I assume by "sum
> of every other row" you don't mean summing Time, X and Y for rows
> 1,3,5,..., ?

I'm trying to get a piecewise sum of every n rows in a given column in
this data set.
> For the sum of sens2[c(1,3,5,...),] for every column (assuming no NA's
> in the data) you could

I do format checking well before getting to this stage in the analysis.
>
>  (1:nrow(sens2) %% 2) %*% as.matrix(sens2)

That does not do what I want... Again, what it should return is a list
of the sum of the current and preceding row.
-- 
Sent from my mobile device
Envoyait de mon portable

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] matrix subsetting

2012-02-13 Thread R. Michael Weylandt
which(x>0)

or 

which(x>0, arr.ind=TRUE)

depending on your application. 

Michael

On Feb 13, 2012, at 5:38 PM, Sam Steingold  wrote:

> if I have a vector, I can find the indexes which satisfy a condition:
> x <- rnorm(10)
> [1]  0.4751132 -0.5442322 -0.1979854 -0.2455521  0.8349336 -0.4283345
> [7]  0.6108130  2.0576160  1.1251716 -1.3933637
> x[x>0]
> [1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716
> (1:10)[x>0]
> [1] 1 5 7 8 9
> 
> how about a matrix?
> 
>   0G  0Q  2O   35   37   3A
> 0G NA 0.008226002 0.005631718 0.0002625585 0.0010673235 0.0045310915
> 0Q NA  NA 0.003714951 0.0002007877 0.0016983426 0.0011083925
> 2O NA  NA  NA 0.0024233691 0.0069849678 0.0024510792
> 35 NA  NA  NA   NA 0.0006499707 0.0008420414
> 37 NA  NA  NA   NA   NA 0.0005448872
> 3A NA  NA  NA   NA   NA   NA
> 3B NA  NA  NA   NA   NA   NA
> 3G NA  NA  NA   NA   NA   NA
> 3H NA  NA  NA   NA   NA   NA
> 3I NA  NA  NA   NA   NA   NA
> 3B   3G   3H  3I
> 0G 0.0007254316 0.0093954826 3.420231e-04 0.003974556
> 0Q 0.0013883606 0.0019778247 3.609791e-05 0.001552725
> 2O 0.0027340806 0.0082790646 2.561862e-03 0.012297821
> 35 0.0006025767 0.0004534397 1.053946e-03 0.001681780
> 37 0.0005501974 0.0021137871 1.733880e-03 0.003712675
> 3A 0.0008969849 0.0043855527 2.786194e-06 0.002492954
> 3B   NA 0.0019791290 8.301787e-04 0.002816774
> 3G   NA   NA 3.181892e-07 0.010608717
> 3H   NA   NA   NA 0.001066141
> 3I   NA   NA   NA  NA
> 
> how do I find the cells whose values are, e.g., > 0.01 ??
> 
> thanks!
> 
> -- 
> Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
> 11.0.11004000
> http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
> http://ffii.org http://iris.org.il http://truepeace.org http://dhimmi.com
> The difference between genius and stupidity is that genius has its limits.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] only 0s may be mixed with negative subscripts

2012-02-13 Thread ilai
The function you posted runs without error (on these 6 lines), but
does not return anything that looks remotely like a sum, or cumsum of
anything. Can you clarify what you are trying to do? I assume by "sum
of every other row" you don't mean summing Time, X and Y for rows
1,3,5,..., ?

For the sum of sens2[c(1,3,5,...),] for every column (assuming no NA's
in the data) you could

 (1:nrow(sens2) %% 2) %*% as.matrix(sens2)

   Time   Y X rownumber
[1,] 3985695201 0.56826 0.1369527 9

Hope this helps


On Mon, Feb 13, 2012 at 11:56 AM, Hasan Diwan  wrote:
> I'd like to get the sum of every other row in a data.frame. When I
> actually set about doing this, I get the error in the subject line of
> this message. A sample of my data is below, followed by the function
> call that should give me the results I want:
>
>> dput(head(sens2))
> structure(list(Time = c(1328565067, 1328565067.05, 1328565067.1,
> 1328565067.15, 1328565067.2, 1328565067.25), Y = c(0.0963890795246276,
> 0.227296347215609, 0.240972698811569, 0.221208948983498, 0.230898231782485,
> 0.203282153087549), X = c(0.0245045248243853, 0.0835679411703579,
> 0.0612613120609633, 0.058568910563872, 0.0511868450318788, 0.0557714205674231
> ), rownumber = 1:6), .Names = c("Time", "Y", "X", "rownumber"
> ), row.names = c(NA, 6L), class = "data.frame")
>> speedX <- sapply(sens2[sens2$rownumber %% 2 == 0,], function(row) { 
>> cumsum(c(sens2[row+1,3], sens2[row,3]))}, simplify=TRUE)
> Error in xj[i] : only 0's may be mixed with negative subscripts
> Help?
> --
> Sent from my mobile device
> Envoyait de mon portable
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] survey package svystat objects from predict()

2012-02-13 Thread Kieran Healy
Hello, 

I'm running R 2.14.1 on OS X (x86_64-apple-darwin9.8.0/x86_64 (64-bit)), with 
version 3.28 of Thomas Lumley's survey package. I was using predict() from 
svyglm(). E.g.:

data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
out <- svyglm(sch.wide~ell+mobility, design=dstrat,
family=quasibinomial())
pred.df <- expand.grid(ell=c(20,50,80), mobility=20)
out.pred <- predict(out, pred.df)

>From the console out.pred looks like this:

> class(out.pred)
[1] "svystat"

> print(out.pred) # or just 'out.pred'
link SE
1 1.8504 0.2414
2 1.6814 0.3033
3 1.5124 0.5197

>From here I wanted to conveniently access the predicted values and SEs. I 
>thought that I might be able to do this using either ftable() or 
>as.data.frame(), as methods for these exist for the objects of class 
>"svystat". But while the predicted values come through fine, the SE only gets 
>calculated for the first element and is then repeated: 

> ftable(out.pred)
  A B
1 1.8504120 0.2413889
2 1.6814293 0.2413889
3 1.5124466 0.2413889

> as.data.frame(out.pred)
  linkSE
1 1.850412 0.2413889
2 1.681429 0.2413889
3 1.512447 0.2413889

I think what's happening is that as.data.frame.svystat() method in the survey 
package ends up calling the wrong function to calculate the standard errors.  
From the survey package:

as.data.frame.svystat<-function(x,...){
  rval<-data.frame(statistic=coef(x),SE=SE(x))
  names(rval)[1]<-attr(x,"statistic")
  if (!is.null(attr(x,"deff")))
rval<-cbind(rval,deff=deff(x))
  rval
}

The relevant SE method seems to be: 

SE.svrepstat<-function(object,...){
  if (is.list(object)){
object<-object[[1]]
  }
  vv<-as.matrix(attr(object,"var"))
  if (!is.null(dim(object)) && length(object)==length(vv))
sqrt(vv)
  else
sqrt(diag(vv))
}

Instead of returning sqrt(vv) on each element, it calculates sort(diag(vv)) 
instead. At least I think this is what's happening. 

I apologize in advance if all this is the result of some elementary error on my 
part. 

Thanks,

Kieran
  
-- 
Kieran Healy :: http://kieranhealy.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] Change dataframe-structure

2012-02-13 Thread Justin Haynes
There is probably a more ellegant way, but:

> df <-
data.frame(p1=c(1,2,1),p2=c(3,3,2),p3=c(2,1,3),p4=c(5,6,4),p5=c(4,4,6),p6=c(6,5,5))
> as.data.frame(t(apply(df,1,function(x) names(x)[match(1:6,x)])))
  V1 V2 V3 V4 V5 V6
1 p1 p3 p2 p5 p4 p6
2 p3 p1 p2 p5 p6 p4
3 p1 p2 p3 p4 p6 p5
>


On Mon, Feb 13, 2012 at 2:07 PM, David Studer  wrote:

> Hello everybody,
>
> I have the following problem and have no idea how to solve it:
>
> In my dataframe I have six columns representing six societal problems (p1,
> p2, ..., p6).
> The values are ranks between 1 (worst problem) and 6 (best problem)
>
>
> p1 p2 p3  p4 p5 p6
> 1   3   2   5   4   6
> 2   3   1   6   4   5
> 1   2   3   4   6   5
>
> but I'd like the dataframe the other way round:
> 123456
> p1  p3  p2  p4  p4  p6
> p3  p1  p2  p5  p6  p4
> p1  p2  p3  p4  p6  p5
>
> Can anyone help?
>
> Thanks!
>
>[[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] Change dataframe-structure

2012-02-13 Thread Bert Gunter
P <- paste("P",1:6,sep="")
t(apply(yourdataframe,1,function(x)P[order(x)]))

## result is a mtrix, though.

-- Bert


On Mon, Feb 13, 2012 at 2:07 PM, David Studer  wrote:
> Hello everybody,
>
> I have the following problem and have no idea how to solve it:
>
> In my dataframe I have six columns representing six societal problems (p1,
> p2, ..., p6).
> The values are ranks between 1 (worst problem) and 6 (best problem)
>
>
> p1 p2 p3  p4 p5 p6
> 1   3   2   5   4   6
> 2   3   1   6   4   5
> 1   2   3   4   6   5
>
> but I'd like the dataframe the other way round:
> 1    2    3    4    5    6
> p1  p3  p2  p4  p4  p6
> p3  p1  p2  p5  p6  p4
> p1  p2  p3  p4  p6  p5
>
> Can anyone help?
>
> Thanks!
>
>        [[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] Change dataframe-structure

2012-02-13 Thread Gabor Grothendieck
On Mon, Feb 13, 2012 at 5:07 PM, David Studer  wrote:
> Hello everybody,
>
> I have the following problem and have no idea how to solve it:
>
> In my dataframe I have six columns representing six societal problems (p1,
> p2, ..., p6).
> The values are ranks between 1 (worst problem) and 6 (best problem)
>
>
> p1 p2 p3  p4 p5 p6
> 1   3   2   5   4   6
> 2   3   1   6   4   5
> 1   2   3   4   6   5
>
> but I'd like the dataframe the other way round:
> 1    2    3    4    5    6
> p1  p3  p2  p4  p4  p6
> p3  p1  p2  p5  p6  p4
> p1  p2  p3  p4  p6  p5
>


First we read the data and then rearrange it into long form (DF) and
turn that into a 2d matrix (tapply):

Lines <- "p1 p2 p3  p4 p5 p6
1   3   2   5   4   6
2   3   1   6   4   5
1   2   3   4   6   5"
DF0 <- read.table(text = Lines, header = TRUE)

DF <-  as.data.frame.table(as.matrix(DF0), stringsAsFactors = FALSE,
responseName = "Ranks")
tapply(DF[["Var2"]], DF[-2], c)

The result of the last statement is:

Ranks
Var1 123456
   A "p1" "p3" "p2" "p5" "p4" "p6"
   B "p3" "p1" "p2" "p5" "p6" "p4"
   C "p1" "p2" "p3" "p4" "p6" "p5"

-- 
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] matrix subsetting

2012-02-13 Thread Sam Steingold
if I have a vector, I can find the indexes which satisfy a condition:
x <- rnorm(10)
 [1]  0.4751132 -0.5442322 -0.1979854 -0.2455521  0.8349336 -0.4283345
 [7]  0.6108130  2.0576160  1.1251716 -1.3933637
x[x>0]
[1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716
(1:10)[x>0]
[1] 1 5 7 8 9

how about a matrix?

   0G  0Q  2O   35   37   3A
0G NA 0.008226002 0.005631718 0.0002625585 0.0010673235 0.0045310915
0Q NA  NA 0.003714951 0.0002007877 0.0016983426 0.0011083925
2O NA  NA  NA 0.0024233691 0.0069849678 0.0024510792
35 NA  NA  NA   NA 0.0006499707 0.0008420414
37 NA  NA  NA   NA   NA 0.0005448872
3A NA  NA  NA   NA   NA   NA
3B NA  NA  NA   NA   NA   NA
3G NA  NA  NA   NA   NA   NA
3H NA  NA  NA   NA   NA   NA
3I NA  NA  NA   NA   NA   NA
 3B   3G   3H  3I
0G 0.0007254316 0.0093954826 3.420231e-04 0.003974556
0Q 0.0013883606 0.0019778247 3.609791e-05 0.001552725
2O 0.0027340806 0.0082790646 2.561862e-03 0.012297821
35 0.0006025767 0.0004534397 1.053946e-03 0.001681780
37 0.0005501974 0.0021137871 1.733880e-03 0.003712675
3A 0.0008969849 0.0043855527 2.786194e-06 0.002492954
3B   NA 0.0019791290 8.301787e-04 0.002816774
3G   NA   NA 3.181892e-07 0.010608717
3H   NA   NA   NA 0.001066141
3I   NA   NA   NA  NA

how do I find the cells whose values are, e.g., > 0.01 ??

thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://pmw.org.il http://americancensorship.org
http://ffii.org http://iris.org.il http://truepeace.org http://dhimmi.com
The difference between genius and stupidity is that genius has its limits.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non-isomorphic sequences

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 02:04:51PM -0800, zheng wei wrote:
> Dear Petr,
>  
> This is fantastic!
>  
> I have one more question, when p=4, tt=4. We have 15 non-isomorphic sequences 
> as you have generated. Among these 15, I selected 2 sequences. How do I 
> recover all the members of the equivalent classes corresponding to these 2 
> sequences? For example, corresponding to the sequence of , I would like 
> to recover ,,, from this sequence.

Dear Wei:

Try the following.

  getEquivalent <- function(a, tt)
  {
  b <- as.matrix(rev(expand.grid(rep(list(1:tt), times=max(a)
  ok <- apply(b, 1, function(x) length(unique(x))) == ncol(b)
  b <- b[ok, , drop=FALSE]
  dimnames(b) <- NULL
  t(apply(b, 1, function(x) x[a]))
  }

  getEquivalent(c(1, 1, 1, 1), 4)

   [,1] [,2] [,3] [,4]
  [1,]1111
  [2,]2222
  [3,]3333
  [4,]4444

  getEquivalent(c(1, 1, 1, 2), 4)

[,1] [,2] [,3] [,4]
   [1,]1112
   [2,]1113
   [3,]1114
   [4,]2221
   [5,]2223
   [6,]2224
   [7,]3331
   [8,]3332
   [9,]3334
  [10,]4441
  [11,]4442
  [12,]4443

Hope this helps.

Petr.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non-isomorphic sequences

2012-02-13 Thread zheng wei
Dear Petr,
 
This is fantastic!
 
I have one more question, when p=4, tt=4. We have 15 non-isomorphic sequences 
as you have generated. Among these 15, I selected 2 sequences. How do I recover 
all the members of the equivalent classes corresponding to these 2 sequences? 
For example, corresponding to the sequence of , I would like to recover 
,,, from this sequence.
 
Thanks,
Wei



From: Petr Savicky 
To: r-help@r-project.org 
Sent: Monday, February 13, 2012 2:53 PM
Subject: Re: [R] non-isomorphic sequences

On Mon, Feb 13, 2012 at 10:05:02AM -0800, zheng wei wrote:
> Dear All,
> 
> Sorry for the typoes earlier, let me repost the question.
> 
> Suppose I want to generate sequences of length 3 from two symbols {1,2}, we 
> get the following 8 sequences
> 1 1 1
> 1 1 2
> 1 2 1
> 1 2 2
> 2 1 1
> 2 1 2
> 2 2 1
> 2 2 2
> 
> However, I do not want all these 8 sequences. I call two sequencs to be 
> isomorphic if one sequence could be obtained from the other by relabelling 
> the symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 
> 221.?By eliminating all these isomorphic ones, what I want is the following
> 1 1 1
> 1 1 2
> 1 2 1
> 2 1 1

Eliminating isomorphic sequences may be done differently,
if we select different representatives of each equivalence
class. The following also eliminates isomorphic 1,2 sequences

  1 1 1
  1 1 2
  1 2 1
  1 2 2

Is this solution OK?

> In general, I need to generate non-isomorphic sequences of length p from t 
> distinct symbols. For example, when p=3, t=3 we have
> matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)
> 
> [1,]??? 1??? 1??? 2??? 1??? 1
> [2,]??? 2??? 1??? 1??? 2??? 1
> [3,]??? 3??? 2??? 1??? 1??? 1
> 
> When p=4, t=4 we have
> matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)
> 
> [1,]??? 1??? 1??? 1??? 1??? 2??? 2??? 2??? 1??? 1 1 1 1 1 
> 2 1
> [2,]??? 2??? 1??? 2??? 2??? 1??? 3??? 1??? 1??? 2 2 1 1 2 
> 1 1
> [3,]??? 3??? 2??? 1??? 3??? 1??? 1??? 3??? 2??? 1 2 1 2 1 
> 1 1
> [4,]??? 4??? 3??? 3??? 1??? 3??? 1??? 1??? 2??? 2 1 2 1 1 
> 1 1
> 
> 
> In general, I need to do this for arbitrary choices of p and t.

If p and t are not too large, try the following

  check.row <- function(x)
  {
      y <- unique(x)
      all(y == seq.int(along=y))
  }

  p <- 4
  tt <- 4 # do not rewrite t() for transpose
  elem <- lapply(as.list(pmin(1:p, tt)), function(x) seq.int(length=x))
  a <- as.matrix(rev(expand.grid(rev(elem
  ok <- apply(a, 1, check.row)
  out <- a[ok, ]
  out

        Var4 Var3 Var2 Var1
  [1,]    1    1    1    1
  [2,]    1    1    1    2
  [3,]    1    1    2    1
  [4,]    1    1    2    2
  [5,]    1    1    2    3
  [6,]    1    2    1    1
  [7,]    1    2    1    2
  [8,]    1    2    1    3
  [9,]    1    2    2    1
  [10,]    1    2    2    2
  [11,]    1    2    2    3
  [12,]    1    2    3    1
  [13,]    1    2    3    2
  [14,]    1    2    3    3
  [15,]    1    2    3    4

This solution differs from yours, for example, in
the row c(1, 2, 3, 3), which is in your solution
represented by c(2, 3, 1, 1). This a different choice
of the representatives. Is the choice important?

A related thread started at

  https://stat.ethz.ch/pipermail/r-help/2012-January/301489.html

There was an additional requirement that each of t symbols
has at least one occurrence.

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error Message Comes from the Vuong Function

2012-02-13 Thread mikezhaow
I want to compare the poisson and the zero-inflated poisson distribution on
describing the data.  So, after using the GLM and the ZEROINFL function, I
used the Voung function to compare them.  Here is my code:

library(pscl)
glm1 <- glm(nmer9_1[, 1] ~ 1, family = poisson)
zip <- zeroinfl(nmer9_1[, 1] ~ 1)
vuong(glm1, zip)

However, R returns the following error message:
"Error: cannot allocate vector of size 3.3 Gb."

Would you please tell me what was happening there?  Please note that I am
not trying to do a regression, but only want to compare which of the
distributions explain the data better.

Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-Message-Comes-from-the-Vuong-Function-tp4385497p4385497.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] If (x > 0)

2012-02-13 Thread Schmidt, Michael
Hi,
I am new to R. I was trying to get a very simple program to run. Take one 
number from the command line. If the number < 0 return -1. If number > 0 return 
1 and if the number == 0 return 0. The code is in a file called test1.R


The code:

#useage: R --no-save --args 5 < test1.R
args = (commandArgs(TRUE))
x = as.numeric(args[1])
print(x)

res <- conditional1(x)
cat("result= ",res,"\n")

conditional1 <- function(x){
result <- 0
if (x > 0) {
result <- 1
} else if (x < 0) {
result <- -1
}
return(result)
}


The output:
>R --no-save --slave --args 1 < test1.R
[1] 1
result=  1
>R --no-save --slave --args -1 < test1.R
[1] -1
result=  -1
>] R --no-save --slave --args 0 < test1.R
[1] 0
result=  -1


The problem:
For arguments 1 and -1 it works as intended. For 0 (zero) it does not. If the 0 
value is passed into the function named "conditional1"  I would expect both 
if-statements to evaluate to false and 0 being return. From what I can tell (0 
< 0) evaluates to true since -1 is returned. Hm...
What is going on? What am I doing wrong? Why is this happening? I am baffled!
Any help would be appreciated.
Thanks
Mike




[[alternative HTML version deleted]]

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


[R] Change dataframe-structure

2012-02-13 Thread David Studer
Hello everybody,

I have the following problem and have no idea how to solve it:

In my dataframe I have six columns representing six societal problems (p1,
p2, ..., p6).
The values are ranks between 1 (worst problem) and 6 (best problem)


p1 p2 p3  p4 p5 p6
1   3   2   5   4   6
2   3   1   6   4   5
1   2   3   4   6   5

but I'd like the dataframe the other way round:
123456
p1  p3  p2  p4  p4  p6
p3  p1  p2  p5  p6  p4
p1  p2  p3  p4  p6  p5

Can anyone help?

Thanks!

[[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] Writing R-scripts

2012-02-13 Thread Cem Girit
Hello,

This is my first attempt to write a script in R. The program below
is intended to do some parametric tests on group data. There are subroutines
for each type of test. The call to the "parametric.tests", routine sets the
argument "testtype" for the test to be used. How can I transfer the
calculated values (in "result" below) in each routine to the calling
parametric.tests routine?  

Cem




## testtype : 1: Duncan
## 2: Dunnett
## resp:  response variable, must be numeric and vector
## group: group id for resp, numeric or character
## alpha: CL 0.05 or 0.01
## vehicle: Control group name for Dunnett

parametric.tests<-function(testtype, resp, group, vehicle, alpha)
{
if (testtype==1){
 
## resp:  response variable, must be numeric and vector
## group: group id for resp, numeric or character
## alpha: CL 0.05 or 0.01

 duncan.test <- function (resp, group, alpha) {

.

result <- data.frame(label=label, estimate=Estimate, alpha=alpha,
lower=Lower, upper=Upper, p.value=pval, significance=sig)
return(result)
}
}

else if (testtype==2){


dunnett.test <- function(resp, group, vehicle, alpha)
{

.
 
 result <- data.frame(label=label, estimate=Estimate, alpha=alpha,
lower=Lower, upper=Upper, p.value=pval, significance=sig)
 return(result)
}
}
}

Cem

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] entropy package: how to compute mutual information?

2012-02-13 Thread Sam Steingold
> * Sam Steingold  [2012-02-13 16:14:36 -0500]:
>
> suppose I have two factor vectors:
>  x <- as.factor(c("a","b","a","c","b","c"))
>  y <- as.factor(c("b","a","a","c","c","b"))
> I can compute their entropies:
>  entropy(table(x))
> [1] 1.098612
> using
>  library(entropy)
> but it is not clear how to compute their mutual information directly.
> I can compute the joint entropy as
>   entropy(table(paste(x,y,sep="")))

this can be simplified to entropy(table(x,y))

> [1] 1.791759
> and then mutual information will be h(x) + h(y) - h(x,y) =
> 1.098612 + 1.098612 - 1.791759
> 0.405465
>
> but I was wondering whether there was a better way (without creating a
> fresh factor vector and a fresh factor class, both of which are
> immediately discarded).

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://ffii.org http://mideasttruth.com
http://thereligionofpeace.com http://americancensorship.org http://memri.org
If money were measured in piles, I would have had a pit of it.

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


Re: [R] for loop

2012-02-13 Thread eddie smith
Dear Ted,

Thank you very much for your details explanation!

Cheers.

On Mon, Feb 13, 2012 at 7:12 PM, Ted Harding wrote:

> In addition to Jim's neat solution (see also below),
> some comments on your original code.
>
> Your "for" loop executes x=29.5 + i/500 100 times,
> producing a single value each time and replacing the
> previous value which was in x. So, at the end of the loop,
> you have a single value of x. Then you "compute" y=2x;
> that, as it stands, would prokoke an error:
>
>  Error: unexpected symbol in "y=2x"
>
> since variable names cannort start with a digit. You
> need, of course, the mutltiplaction operator "*" as
> in Jim's "y <- 2 * x".
>
> The scope of your "for" loop (i.e. the set of commands
> that is executed for each round of the loop) is solely
> the command "x=29.5 + i/500". The "y <- 2 * x" is not
> part of the scope of the loop, and would only be executed
> once, when the loop was finished. You would need
>
>   for(i in 1:1000) {
> 
>   }
>
> to cause the execution of several commands in each round
> of the loop.
>
> Finally, even if you did think that your entire series of
> commands (re-written):
>
>  for(i in 1:1000)
>  x=29.5 + i/500
>   y=2*x
>  plot(y,x)
>
> would all be executed (down to and including the plot() command)
> in each round of the loop, nevertheless each call to plot()
> creates a new graph, discarding the previous one, so only a single
> point would be plotted each time.
>
> The solution (as in Jim's suggestion) is to create the full vector
> of x-values and y-values, and then use plot(x,y) where x and y are
> now vectors.
>
> There are all sorts of little details about how R puts things
> together, which will become familiar as you use R. However,
> you do need to get hold of the basics of how R operates, so
> I would suggest having "R for Beginners"
>
>  http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf
>
> to hand while you learn R. It is very good about how the basics
> work. The next step up would be the more systematic exposition
> of how R works in  "An Introduction to R":
>
>  http://cran.r-project.org/doc/manuals/R-intro.html
>  http://cran.r-project.org/doc/manuals/R-intro.pdf
>
> Hoping this helps!
> Ted.
>
> On 13-Feb-2012 jim holtman wrote:
> > x <- 29.5 + (1:1000)/500
> > y <- 2 * x
> > plot(y,x)
> >
> > On Mon, Feb 13, 2012 at 1:34 PM, eddie smith  wrote:
> >> Hi guys,
> >>
> >> This is a very beginner question. Anybody willing to help?
> >>
> >> for(i in 1:1000)
> >> x=29.5 + i/500
> >> y=2x
> >> plot(y,x)
> >>
> >> The idea is to produce 1000 values of x and y then plot them.
> >>
> >> Cheers,
> >> Eddie
> >>
> >> _ _ _ _[[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.
> >
> >
> >
> > --
> > Jim Holtman
> > Data Munger Guru
> >
> > What is the problem that you are trying to solve?
> > Tell me what you want to do, not how you want to do it.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> -
> E-Mail: (Ted Harding) 
> Date: 13-Feb-2012  Time: 19:12:47
> This message was sent by XFMail
> -
>

[[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] entropy package: how to compute mutual information?

2012-02-13 Thread Sam Steingold
suppose I have two factor vectors:
 x <- as.factor(c("a","b","a","c","b","c"))
 y <- as.factor(c("b","a","a","c","c","b"))
I can compute their entropies:
 entropy(table(x))
[1] 1.098612
using
 library(entropy)
but it is not clear how to compute their mutual information directly.
I can compute the joint entropy as
  entropy(table(paste(x,y,sep="")))
[1] 1.791759
and then mutual information will be h(x) + h(y) - h(x,y) =
1.098612 + 1.098612 - 1.791759
0.405465

but I was wondering whether there was a better way (without creating a
fresh factor vector and a fresh factor class, both of which are
immediately discarded).


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il http://ffii.org http://camera.org
http://americancensorship.org http://dhimmi.com http://pmw.org.il
There is Truth, and its value is T.  Or just non-NIL.  So 0 is True!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] access R basic libraries

2012-02-13 Thread Berend Hasselman

On 13-02-2012, at 21:47, nitin kumar wrote:

> Hello Everyone,
> I am trying to access all R basic C/Fotran libraries to see how some
> functions are written in fotran or C so that in case I need to change some
> stuff I can do that.
> 

BTW; it's fortran.

Well, goto CRAN (http://cran.r-project.org/) and download the sources (link  
R-2.14.1.tar.gz).
Unpack and browse.

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MCMCglmm with cross-classified random effects

2012-02-13 Thread Ben Bolker
Agostino Moro  gmail.com> writes:

> I would like to fit  a glmm with cross-classified random effects with
> the function MCMCglmm. Something along the lines:
> 
> model1<-MCMCglmm(response~pred1, random=~re1+re2, data=data)
> 
> where re1 and re2 should be crossed random effects.

 [snip to make gmane happy. Thank you for trying to find the answer
before posting ...]

  It would probably be best to post this one to the r-sig-mixed-models
 r-project.org mailing list instead ...

  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] access R basic libraries

2012-02-13 Thread nitin kumar
Hello Everyone,
I am trying to access all R basic C/Fotran libraries to see how some
functions are written in fotran or C so that in case I need to change some
stuff I can do that.

Any help would be great,
nitin

[[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] Singling out observations

2012-02-13 Thread Kurt_Helf
Greetings
 I am attempting to plot observations of a cave aquatic invertebrate
dating from 1901-2004.  I can come up with a nice lattice plot of the eight
sites from which I have data easily enough.  However, I'd like to be able
to highlight the 0 observations on the plots, i.e., attempts to find it at
the site were unsuccessful.  I'd like to be able to highlight these
observations with either a symbol or a color.  Here's a sample of the data
(Reach=site):
 (Embedded image moved to file: pic17437.jpg)

Here's my code for the plot:
xyplot(No.Invert~Year|Reach, data=Invert.Coll.1901.2004,
 layout=c(4,2),
   ylab="No. Invert 'collected'",
   scales=list(x=list(rot=45)))

***
Kurt Lewis Helf, Ph.D.
Ecologist
EEO Counselor
National Park Service
Cumberland Piedmont Network
P.O. Box 8
OR
NPS Warehouse
61 Maintenance Rd.
Mammoth Cave, KY 42259
Ph: 270-758-2163
Lab: 270-758-2151
Fax: 270-758-2609
Cumberland Piedmont Network (CUPN) Homepage:
http://tiny.cc/e7cdx
***
Science, in constantly seeking real explanations, reveals the true majesty
of our world in all its complexity.
-Richard Dawkins

[Scientific] theories are passed on not as dogmas but rather with the
challenge to discuss them and improve upon them.
-Karl Popper

...consider yourself a guest in the home of other creatures as significant
as yourself.
-Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains
National Park, TX

CUPN Forest Pest Monitoring Website:
http://bit.ly/9rhUZQ

CUPN Cave Cricket Monitoring Website:
http://tiny.cc/ntcql

CUPN Cave Aquatic Biota Monitoring Website:
http://tiny.cc/n2z1o__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non-isomorphic sequences

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 10:05:02AM -0800, zheng wei wrote:
> Dear All,
> 
> Sorry for the typoes earlier, let me repost the question.
> 
> Suppose I want to generate sequences of length 3 from two symbols {1,2}, we 
> get the following 8 sequences
> 1 1 1
> 1 1 2
> 1 2 1
> 1 2 2
> 2 1 1
> 2 1 2
> 2 2 1
> 2 2 2
> 
> However, I do not want all these 8 sequences. I call two sequencs to be 
> isomorphic if one sequence could be obtained from the other by relabelling 
> the symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 
> 221.?By eliminating all these isomorphic ones, what I want is the following
> 1 1 1
> 1 1 2
> 1 2 1
> 2 1 1

Eliminating isomorphic sequences may be done differently,
if we select different representatives of each equivalence
class. The following also eliminates isomorphic 1,2 sequences

  1 1 1
  1 1 2
  1 2 1
  1 2 2

Is this solution OK?

> In general, I need to generate non-isomorphic sequences of length p from t 
> distinct symbols. For example, when p=3, t=3 we have
> matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)
> 
> [1,]??? 1??? 1??? 2??? 1??? 1
> [2,]??? 2??? 1??? 1??? 2??? 1
> [3,]??? 3??? 2??? 1??? 1??? 1
> 
> When p=4, t=4 we have
> matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)
> 
> [1,]??? 1??? 1??? 1??? 1??? 2??? 2??? 2??? 1??? 1 1 1 1 1 
> 2 1
> [2,]??? 2??? 1??? 2??? 2??? 1??? 3??? 1??? 1??? 2 2 1 1 2 
> 1 1
> [3,]??? 3??? 2??? 1??? 3??? 1??? 1??? 3??? 2??? 1 2 1 2 1 
> 1 1
> [4,]??? 4??? 3??? 3??? 1??? 3??? 1??? 1??? 2??? 2 1 2 1 1 
> 1 1
> 
> 
> In general, I need to do this for arbitrary choices of p and t.

If p and t are not too large, try the following

  check.row <- function(x)
  {
  y <- unique(x)
  all(y == seq.int(along=y))
  }

  p <- 4
  tt <- 4 # do not rewrite t() for transpose
  elem <- lapply(as.list(pmin(1:p, tt)), function(x) seq.int(length=x))
  a <- as.matrix(rev(expand.grid(rev(elem
  ok <- apply(a, 1, check.row)
  out <- a[ok, ]
  out

Var4 Var3 Var2 Var1
   [1,]1111
   [2,]1112
   [3,]1121
   [4,]1122
   [5,]1123
   [6,]1211
   [7,]1212
   [8,]1213
   [9,]1221
  [10,]1222
  [11,]1223
  [12,]1231
  [13,]1232
  [14,]1233
  [15,]1234

This solution differs from yours, for example, in
the row c(1, 2, 3, 3), which is in your solution
represented by c(2, 3, 1, 1). This a different choice
of the representatives. Is the choice important?

A related thread started at

  https://stat.ethz.ch/pipermail/r-help/2012-January/301489.html

There was an additional requirement that each of t symbols
has at least one occurrence.

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] nice report generator?

2012-02-13 Thread Duncan Murdoch

On 06/02/2012 4:12 PM, Hadley Wickham wrote:

>  2. It's more flexible to construct the language object as a language object,
>  rather than pasting something together and parsing it.  For one thing, that
>  allows non-syntactic variable names; I think it's also easier to read.  So
>  your code
>
>  txt<- paste("tabular(value*v*", LEFT , "~" ,RIGHT ,", data = m_xx,
>  suppressLabels  = 2,...)", sep = "")
>  eval(parse(text = txt ))
>
>  could be rewritten as
>
>  formula<- substitute( value*v*LEFT ~ RIGHT, list(LEFT=LEFT, RIGHT=RIGHT))
>  tabular(formula, data = m_xx, suppressLabels = 2, ...)

To be strictly correct, shouldn't that be:

formula<- eval(substitute( value*v*LEFT ~ RIGHT, list(LEFT=LEFT, RIGHT=RIGHT)))

?

>  It might make sense to put something like this into the tables package, but
>  I don't want to have a dependency on reshape.

Would you consider making tabular generic?


I have now made tabular() into a generic function, but because of the 
problems at R-forge, can't commit the changes immediately.   The old 
tabular() function is now the tabular.formula() method; the default 
method tries to coerce the object to a formula to call that.  I think 
both my suggestion and yours would likely have problems in the new 
system (as they did in the old one) because the environment associated 
with the formula would be wrong.  It's a little tricky, but now 
tabular() works a lot more like model.frame(), which I think has to be 
considered to be the standard way to do this.


Duncan Murdoch

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


Re: [R] R's AIC values differ from published values

2012-02-13 Thread Mark Leeds
hi: the definition of AIC can vary a lot from paper to paper and textbook
to textbook because some people keep the multiplicative constants and
other's don't. all that matters when using AIC is COMPARISON. the value
itself means nothing. So, you'll be fine no matter what
you use as long as you're consistent.




On Mon, Feb 13, 2012 at 1:22 PM, david hamer wrote:

> Using the Cement hardening data in Anderson (2008) Model Based Inference in
> the Life Sciences. A Primer on Evidence, and working with the best model
> which is
>lm  (  y  ~   x1   +   x2,data = cement  )
> the AIC value from R is
>
>model<-lm  ( formula   =   y   ~   x1   +  x2  ,   data =
> cement  )
>AIC ( model )
>
> 64.312
>
> which can be converted to AICc by adding the bias correction factor
> 2*K*(K+1)/(n-K-1) to give the AICc value of
> 69.312
> (addition of 5, where n=13 and K=4).
>
> This same value, 69.31, can be obtained using R package
> AICcmodavg
>
>   library  (  AICcmodavg  )
>   data (cement)
>   cement
>   Cand.models   <-   list( )
>   Cand.models[[1]]   <-   lm  (  y  ~   x1   +   x2,data = cement  )
>   Cand.models[[2]]   <-   lm  (  y~   x3   +   x4, data = cement  )
>   Cand.models[[3]]   <-   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
> cement  )
>   Cand.models[[4]]   <-   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
> cement  )
> ##   vector of model names
>   Modnames   <-   paste("MODEL", 1:4, sep=" ")
> ##   AICc
>   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )
>
> However, the AICc value reported by Anderson (2008) is
> 32.41.
> The AICc value obtained using RSS value (i.e., calculating AICc "manually"
> from the output of linear regression) is
> 32.41.
>
> Thanks for any help.
> David
> New R user, minimal familiarity with statistics.
>
>[[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] Puzzling... puzzling... puzzling...

2012-02-13 Thread William Dunlap
Replace the syntax List$Name with List[["Name"]]
and see if things work better.

'[[' does not do the partial matching that '$' does.
E.g.,
   x <- list(AB=10, BC=20, CD=30)
   x$A # returns 10 because "A" is the initial part of exactly one name in x, 
"AB"
   x[["A"]] # returns NULL

However, if you have
   y <- list(AB=1, AC=2, AD=3)
then y$A will return NULL because there is not a unique partial
match to "A" among the names of y.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Michael
> Sent: Monday, February 13, 2012 11:00 AM
> To: r-help
> Subject: [R] Puzzling... puzzling... puzzling...
> 
>  Hi all,
> 
> I made sure that it's "env$sRes1$nPositionsOptimizedM" that's correct...
> 
> not the "env$sRes1$nPositionsOptimized"...
> 
> But it seems both point to the same memory area...
> 
> This is very dangerous because I have used naming conventions such as:
> 
> MyLongVariableNameForA
>  MyLongVariableNameForB
>  MyLongVariableNameForC
> ...
> ...
> 
> Then if internally they are actually the same thing then all my programs
> messed up...
> 
> Any thoughts?
> 
> >env=new.env()
> 
> >load("MyResults.rData", env)
> 
> >identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)
> 
> [1] TRUE
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] R's AIC values differ from published values

2012-02-13 Thread Bert Gunter
This is answered in ?AIC. Have you read it?

-- Bert

On Mon, Feb 13, 2012 at 10:22 AM, david hamer  wrote:
> Using the Cement hardening data in Anderson (2008) Model Based Inference in
> the Life Sciences. A Primer on Evidence, and working with the best model
> which is
>    lm  (  y  ~   x1   +   x2,    data = cement  )
> the AIC value from R is
>
>    model    <-    lm  ( formula   =   y   ~   x1   +  x2  ,   data =
> cement  )
>    AIC ( model )
>
> 64.312
>
> which can be converted to AICc by adding the bias correction factor
> 2*K*(K+1)/(n-K-1) to give the AICc value of
> 69.312
> (addition of 5, where n=13 and K=4).
>
> This same value, 69.31, can be obtained using R package
> AICcmodavg
>
>   library  (  AICcmodavg  )
>   data (cement)
>   cement
>   Cand.models   <-   list( )
>   Cand.models[[1]]   <-   lm  (  y  ~   x1   +   x2,    data = cement  )
>   Cand.models[[2]]   <-   lm  (  y    ~   x3   +   x4,     data = cement  )
>   Cand.models[[3]]   <-   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
> cement  )
>   Cand.models[[4]]   <-   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
> cement  )
>     ##   vector of model names
>   Modnames   <-   paste("MODEL", 1:4, sep="     ")
>     ##   AICc
>   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )
>
> However, the AICc value reported by Anderson (2008) is
> 32.41.
> The AICc value obtained using RSS value (i.e., calculating AICc "manually"
> from the output of linear regression) is
> 32.41.
>
> Thanks for any help.
> David
> New R user, minimal familiarity with statistics.
>
>        [[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.


[R] Question scatterplot axis cut point

2012-02-13 Thread Michael Methlagl
Hi everybody,
i made a scatterplot using the command
plot (datafile1, xlim=c(0,10), ylim=c(0.001, 1), log="y", xlab="x Achse", 
ylab="y Achse", frame.plot=FALSE, axes = TRUE).
Now i  have a problem. There is a gap between the x and the y axis. I want that 
the x and y axis cut at 0 and 0.001 without having this gap.
Is this possible?
thanks for your help!
nice greetings michi
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R's AIC values differ from published values

2012-02-13 Thread david hamer
Using the Cement hardening data in Anderson (2008) Model Based Inference in
the Life Sciences. A Primer on Evidence, and working with the best model
which is
lm  (  y  ~   x1   +   x2,data = cement  )
the AIC value from R is

model<-lm  ( formula   =   y   ~   x1   +  x2  ,   data =
cement  )
AIC ( model )

64.312

which can be converted to AICc by adding the bias correction factor
2*K*(K+1)/(n-K-1) to give the AICc value of
69.312
(addition of 5, where n=13 and K=4).

This same value, 69.31, can be obtained using R package
AICcmodavg

   library  (  AICcmodavg  )
   data (cement)
   cement
   Cand.models   <-   list( )
   Cand.models[[1]]   <-   lm  (  y  ~   x1   +   x2,data = cement  )
   Cand.models[[2]]   <-   lm  (  y~   x3   +   x4, data = cement  )
   Cand.models[[3]]   <-   lm  (  y   ~   x1 + x2 + x1 * x2,   data =
cement  )
   Cand.models[[4]]   <-   lm  (  y   ~   x3  +  x4  +  x3 * x4,   data =
cement  )
 ##   vector of model names
   Modnames   <-   paste("MODEL", 1:4, sep=" ")
 ##   AICc
   aictab   (  cand.set   =   Cand.models,   modnames  =  Modnames  )

However, the AICc value reported by Anderson (2008) is
32.41.
The AICc value obtained using RSS value (i.e., calculating AICc "manually"
from the output of linear regression) is
32.41.

Thanks for any help.
David
New R user, minimal familiarity with statistics.

[[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] Puzzling... puzzling... puzzling...

2012-02-13 Thread Duncan Murdoch

On 13/02/2012 2:00 PM, Michael wrote:

  Hi all,

I made sure that it's "env$sRes1$nPositionsOptimizedM" that's correct...

not the "env$sRes1$nPositionsOptimized"...

But it seems both point to the same memory area...


How did you determine that?  The test below just shows that they contain 
the same thing.



This is very dangerous because I have used naming conventions such as:

MyLongVariableNameForA
  MyLongVariableNameForB
  MyLongVariableNameForC
...
...

Then if internally they are actually the same thing then all my programs
messed up...

Any thoughts?

>env=new.env()

>load("MyResults.rData", env)

>identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)

[1] TRUE


Changing one of them and seeing the other one change would show that 
they point to the same memory area.  This can happen with environments:  
if you create env1 and set env2 <- env1, then changes to either 
environment will affect the other, because that's how environments 
work.   That's not true of most of the other kinds of objects in R.  
(The exceptions are fairly exotic things that you are unlikely to use.)


Duncan Murdoch

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


Re: [R] for loop

2012-02-13 Thread Ted Harding
In addition to Jim's neat solution (see also below),
some comments on your original code.

Your "for" loop executes x=29.5 + i/500 100 times,
producing a single value each time and replacing the
previous value which was in x. So, at the end of the loop,
you have a single value of x. Then you "compute" y=2x;
that, as it stands, would prokoke an error:

  Error: unexpected symbol in "y=2x"

since variable names cannort start with a digit. You
need, of course, the mutltiplaction operator "*" as
in Jim's "y <- 2 * x".

The scope of your "for" loop (i.e. the set of commands
that is executed for each round of the loop) is solely
the command "x=29.5 + i/500". The "y <- 2 * x" is not
part of the scope of the loop, and would only be executed
once, when the loop was finished. You would need

   for(i in 1:1000) {
 
   }

to cause the execution of several commands in each round
of the loop.

Finally, even if you did think that your entire series of
commands (re-written):

  for(i in 1:1000)
  x=29.5 + i/500
  y=2*x
  plot(y,x)

would all be executed (down to and including the plot() command)
in each round of the loop, nevertheless each call to plot()
creates a new graph, discarding the previous one, so only a single
point would be plotted each time.

The solution (as in Jim's suggestion) is to create the full vector
of x-values and y-values, and then use plot(x,y) where x and y are
now vectors.

There are all sorts of little details about how R puts things
together, which will become familiar as you use R. However,
you do need to get hold of the basics of how R operates, so
I would suggest having "R for Beginners"

  http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf

to hand while you learn R. It is very good about how the basics
work. The next step up would be the more systematic exposition
of how R works in  "An Introduction to R":

  http://cran.r-project.org/doc/manuals/R-intro.html
  http://cran.r-project.org/doc/manuals/R-intro.pdf

Hoping this helps!
Ted.

On 13-Feb-2012 jim holtman wrote:
> x <- 29.5 + (1:1000)/500
> y <- 2 * x
> plot(y,x)
> 
> On Mon, Feb 13, 2012 at 1:34 PM, eddie smith  wrote:
>> Hi guys,
>>
>> This is a very beginner question. Anybody willing to help?
>>
>> for(i in 1:1000)
>> x=29.5 + i/500
>> y=2x
>> plot(y,x)
>>
>> The idea is to produce 1000 values of x and y then plot them.
>>
>> Cheers,
>> Eddie
>>
>> _ _ _ _[[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.
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-
E-Mail: (Ted Harding) 
Date: 13-Feb-2012  Time: 19:12:47
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:57 PM, syrvn wrote:


Hi David,

I am using read.xls not read.table.


Please read the help page for read.xls more carefully.



--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384866.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Puzzling... puzzling... puzzling...

2012-02-13 Thread Michael
 Hi all,

I made sure that it's "env$sRes1$nPositionsOptimizedM" that's correct...

not the "env$sRes1$nPositionsOptimized"...

But it seems both point to the same memory area...

This is very dangerous because I have used naming conventions such as:

MyLongVariableNameForA
 MyLongVariableNameForB
 MyLongVariableNameForC
...
...

Then if internally they are actually the same thing then all my programs
messed up...

Any thoughts?

>env=new.env()

>load("MyResults.rData", env)

>identical(env$sRes1$nPositionsOptimized, env$sRes1$nPositionsOptimizedM)

[1] TRUE

[[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] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread syrvn
Hi David,

I am using read.xls not read.table.

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384866.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] Getting codebook data into R

2012-02-13 Thread rmailbox
This is how I get a whole SPSS data files into R. You specifically asked about 
the codebook, so this may not be exactly what you are after. 
 
spssFileInfo <- spss.system.file ( file = "path to my SPSS file" )
spssDataSet <- as.data.set ( spssFileInfo)
spssDataFrame <- as.data.frame ( spssDataSet )

(Not tested. Adapted from working code.) 

memisc documentation has more info about doing this and how it works.

eRic




- Original message -
From: "barny" 
To: r-help@r-project.org
Date: Sat, 11 Feb 2012 10:04:16 -0800 (PST)
Subject: Re: [R] Getting codebook data into R

Hi Eric - after seeing the difficulty of inputting this kind of data into R I
decided to use your method. It was rather painless using PSPP to do what I
wanted - however, how do I now create an SPSS file and then use the memisc
package to read it in?

--
View this message in context: 
http://r.789695.n4.nabble.com/Getting-codebook-data-into-R-tp4374331p4379433.html
Sent from the R help mailing list archive at Nabble.com.

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

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


[R] only 0s may be mixed with negative subscripts

2012-02-13 Thread Hasan Diwan
I'd like to get the sum of every other row in a data.frame. When I
actually set about doing this, I get the error in the subject line of
this message. A sample of my data is below, followed by the function
call that should give me the results I want:

> dput(head(sens2))
structure(list(Time = c(1328565067, 1328565067.05, 1328565067.1,
1328565067.15, 1328565067.2, 1328565067.25), Y = c(0.0963890795246276,
0.227296347215609, 0.240972698811569, 0.221208948983498, 0.230898231782485,
0.203282153087549), X = c(0.0245045248243853, 0.0835679411703579,
0.0612613120609633, 0.058568910563872, 0.0511868450318788, 0.0557714205674231
), rownumber = 1:6), .Names = c("Time", "Y", "X", "rownumber"
), row.names = c(NA, 6L), class = "data.frame")
> speedX <- sapply(sens2[sens2$rownumber %% 2 == 0,], function(row) { 
> cumsum(c(sens2[row+1,3], sens2[row,3]))}, simplify=TRUE)
Error in xj[i] : only 0's may be mixed with negative subscripts
Help?
-- 
Sent from my mobile device
Envoyait de mon portable

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] meboot - can it handle outliers and missing values?

2012-02-13 Thread isabella
 

Hi everyone, 

I would like to use your meboot package in R in a power simulation
study, where meboot stands for Maximum Entropy Bootstrap.

In this study, each time series that will be bootstrapped includes
both missing values and outliers.

Can meboot accomodate these two features, which are the hallmark of
many real time series?  If yes, I would very much appreciate your
thoughts on how this can be achieved in R.   

Many thanks and kind regards,  

Isabella  

Isabella R. Ghement, Ph.D. 
 Ghement Statistical Consulting Company 
 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5 
 Tel: 604-767-1250 
 Fax: 604-270-3922 
 E-mail: isabe...@ghement.ca 
 Web: www.ghement.ca 
 
[[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] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:05 PM, syrvn wrote:


Hi,

thanks for you suggestion.

I finally solved it in a different way using apply and is.na for  
TRUE NA's

and if(as.character(x) == "NA") etc.

However, I just spotted that read.xls seems to have problems reading  
in

special characters such as < or >.


Or could it be that you have problems in not reading the help pages  
carefully?


> read.table(text="")
V1
1 

> read.table(text="", na.strings=c("","NA"))
  V1
1 NA

--

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] for loop

2012-02-13 Thread jim holtman
x <- 29.5 + (1:1000)/500
y <- 2 * x
plot(y,x)

On Mon, Feb 13, 2012 at 1:34 PM, eddie smith  wrote:
> Hi guys,
>
> This is a very beginner question. Anybody willing to help?
>
> for(i in 1:1000)
> x=29.5 + i/500
> y=2x
> plot(y,x)
>
> The idea is to produce 1000 values of x and y then plot them.
>
> Cheers,
> Eddie
>
>        [[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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


[R] for loop

2012-02-13 Thread eddie smith
Hi guys,

This is a very beginner question. Anybody willing to help?

for(i in 1:1000)
x=29.5 + i/500
y=2x
plot(y,x)

The idea is to produce 1000 values of x and y then plot them.

Cheers,
Eddie

[[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] Cumulative density (kernel smoothing)

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 1:01 PM, francogrex wrote:


Hi, in R there is the function "density" which computes kernel density
estimates. Is there a "cumulative" version of it? Something like  
they have

in Matlab:


I'm not aware of one, but you could use `integrate`. You will need to  
limit your range or use the version in package  logspline if your  
range is fixed. You will also need to account for the fact that the  
inteegral will only be approximately == 1. Searching the Archives will  
bring up several similar questions from prior years.\

http://www.mathworks.nl/help/toolbox/stats/ksdensity.html
I know there is ecdf, but I'm not sure it's based on kernel density
smoothing. Thanks



`ecdf` is not based on density.

--

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] best subset selection on random effects model

2012-02-13 Thread ilai
The question is where do your models come from? Passing nested models
to ?anova.lme in nlme package or lme4 results in a likelihood ratio
test. Are you looking for something else/more ?


On Sun, Feb 12, 2012 at 8:02 PM, Tao Zhang  wrote:
> Hi,
>     I know leaps() computes the best subset selection for linear model,
> and the bestglm() computes the best subset selection for generalized linear
> model.
> Is there any package for best subset selection on random effects model, or
> mixed effects model?
>
> Thank you so much.
>
> Tao
>
>        [[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] non-isomorphic sequences

2012-02-13 Thread zheng wei
Dear All,

Sorry for the typoes earlier, let me repost the question.

Suppose I want to generate sequences of length 3 from two symbols {1,2}, we get 
the following 8 sequences
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

However, I do not want all these 8 sequences. I call two sequencs to be 
isomorphic if one sequence could be obtained from the other by relabelling the 
symbols. For example, 111 is isomorphic to 222, 112 is isomorphic to 221. By 
eliminating all these isomorphic ones, what I want is the following
1 1 1
1 1 2
1 2 1
2 1 1

In general, I need to generate non-isomorphic sequences of length p from t 
distinct symbols. For example, when p=3, t=3 we have
matrix(c(1,2,3,1,1,2,2,1,1,1,2,1,1,1,1),3,5)

[1,]    1    1    2    1    1
[2,]    2    1    1    2    1
[3,]    3    2    1    1    1

When p=4, t=4 we have
matrix(c(1,2,3,4,1,1,2,3,1,2,1,3,1,2,3,1,2,1,1,3,2,3,1,1,2,1,3,1,1,1,2,2,1,2,1,2,1,2,2,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1),4,15)

[1,]    1    1    1    1    2    2    2    1    1 1 1 1 1 
2 1
[2,]    2    1    2    2    1    3    1    1    2 2 1 1 2 
1 1
[3,]    3    2    1    3    1    1    3    2    1 2 1 2 1 
1 1
[4,]    4    3    3    1    3    1    1    2    2 1 2 1 1 
1 1


In general, I need to do this for arbitrary choices of p and t.

Thaks a lot,
Wei
[[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] Logistic regression with non-gaussian random effects

2012-02-13 Thread Line Skotte
Hi,
does anyone know of an implementation of generalized linear models with random 
effects, where the random effects are non-gaussian?

Actually, what I need is to do a logistic regression (or binomial regression) 
where the linear predictor in addition to fixed effects and gaussian random 
effects also has a term

b*z

where z is a random effect variable with p(z=1)=p(z=-1)=0.5 and b is a 
parameter of interest. 

I am very grateful to you for any help or comments.

Sincerely,
Line
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread hithit168
Thanks.

I use the bootstrap() function from the bootstrap package. Let me try it
again to see if I get any luck :)

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384608.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] Including .exe files in an R package

2012-02-13 Thread Prof Brian Ripley

On 13/02/2012 17:15, sahir bhatnagar wrote:

I am in the process of creating a package in R which calls
pre-compiled C code i.e. '.exe' files


Which are only used on Windows, so presumably you forgot to mention that OS.


In reading the manual, I came across this:

"A source package if possible should not contain binary executable
files: they are not portable, and a security risk if they are of the
appropriate architecture. R CMD check will warn about them2 unless
they are listed (one filepath per line) in a file ‘BinaryFiles’ at the
top level of the package. Note that CRAN will no longer accept
submissions containing binary files even if they are listed."


From my understanding, the .exe files are a subset of binary files,

which are no longer accepted by CRAN. If this is the case for my
situation, is there any other way to include the C code, so that CRAN
will accept the package?


CRAN will neither accept packages with binary code files, nor will it 
accept packages tied to one architecture and OS (as such files would 
be).  You can do what you like provided you do not want to distribute 
the package: at that point you need to meet the conditions of the 
license and of the repository.


There are several examples of CRAN packages which compile up 
executables: arulesSequences is one.  But note that this is tricky as 
platforms such as Windows and OS X support multiple architectures in the 
same package installation.



thanks

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


And that does make clear that this is (or would rapidly become) a 
R-devel topic.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread syrvn
Hi,

thanks for you suggestion.

I finally solved it in a different way using apply and is.na for TRUE NA's
and if(as.character(x) == "NA") etc.

However, I just spotted that read.xls seems to have problems reading in
special characters such as < or >.

Is there any workaround for that?

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384663.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] Cumulative density (kernel smoothing)

2012-02-13 Thread francogrex
Hi, in R there is the function "density" which computes kernel density
estimates. Is there a "cumulative" version of it? Something like they have
in Matlab:
http://www.mathworks.nl/help/toolbox/stats/ksdensity.html
I know there is ecdf, but I'm not sure it's based on kernel density
smoothing. Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Cumulative-density-kernel-smoothing-tp4384652p4384652.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] pairwise comparisons with multcomp package

2012-02-13 Thread gaiarrido
Hi,
I've got this model and following Hothorn et al advices, I used glht for a
post hoc comparison


> modezqM<-glm(rojos~estacion*zona3,quasipoisson,subset=(edadysexo=="M"))
> anova(modezqM,test="F") 
 Df  Deviance  Resid. Df Resid.
Dev   F   Pr(>F)
NULL293 41148  
estacion  1 3647.0   292 37501  
 
23.6250  1.927e-06 ***
zona3  2   931.4   290 36569
 
3.0167   0.050510.  
estacion:zona3  2 2421.7   28834148 
7.84380.000482 ***  


> summary(glht(modezqM,linfct=mcp(zona3="Tukey",interaction_average=T))) 
   Estimate   Std. Error  z-value  
Pr(>|z|)  
norte - turist == 0 -0.051820.23701  -0.219 0.9727  
occid - turist == 0 -1.059700.41618  -2.546 0.0271 *
occid - norte == 0 -1.007880.45830  -2.199 0.0665 .

I'm trying to understanding the way this command made pairwise comparisons,
but, where does this z-value comes from?  
I'm suspected this not come from Tukey's test, but i don't know it's Wald or
something i've never use
I know it is not an habitual doubt.
Sorry and thanks in advance

I suspect it


-
Mario Garrido Escudero
PhD student
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca. Agrícola
Universidad de Salamanca
--
View this message in context: 
http://r.789695.n4.nabble.com/pairwise-comparisons-with-multcomp-package-tp4384499p4384499.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] Including .exe files in an R package

2012-02-13 Thread sahir bhatnagar
I am in the process of creating a package in R which calls
pre-compiled C code i.e. '.exe' files

In reading the manual, I came across this:

"A source package if possible should not contain binary executable
files: they are not portable, and a security risk if they are of the
appropriate architecture. R CMD check will warn about them2 unless
they are listed (one filepath per line) in a file ‘BinaryFiles’ at the
top level of the package. Note that CRAN will no longer accept
submissions containing binary files even if they are listed."

>From my understanding, the .exe files are a subset of binary files,
which are no longer accepted by CRAN. If this is the case for my
situation, is there any other way to include the C code, so that CRAN
will accept the package?

thanks

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread R. Michael Weylandt
What package is the bootstrap() function from? There are many
functions by that name

My hunch is that it takes a vector at a time and puts it through
dif.mns so that leads to the error in the apply() call but I can't
verify.

Michael

On Mon, Feb 13, 2012 at 10:34 AM, hithit168  wrote:
> Thank you for your help, David. I was trying to run bootrapping on the
> dataset "shoes" from MASS package. But I still have some problem here.
>
>> as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
> A B
> [1,] 13.2 14.0
> [2,] 8.2 8.8
> [3,] 10.9 11.2
> [4,] 14.3 14.2
> [5,] 10.7 11.8
> [6,] 6.6 6.4
> [7,] 9.5 9.8
> [8,] 10.8 11.3
> [9,] 8.8 9.3
> [10,] 13.3 13.6
>> y=as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
>> class(y)
> [1] "matrix"
>> apply(y,1,diff)
> [1] 0.8 0.6 0.3 -0.1 1.1 -0.2 0.3 0.5 0.5 0.3
>> dif.mns <- function(x2,tr1=.1,tr2=.2){
> + diffs=apply(x2,1,diff)
> + mn1=mean(diffs)
> + mn2=mean(diffs,tr=.1)
> + mn3=mean(diffs,tr=.2)
> + mn4=median(diffs)
> + mns=c(mn1,mn2,mn3,mn4)
> + list(mnds=round(mns,3))}
>> dif.mns(y,tr1=.1,tr2=.2)
> $mnds
> [1] 0.410 0.400 0.417 0.400
>
>> bootstrap(y,nboot=1000,theta=dif.mns)
> Error in apply(x2, 1, diff) : dim(X) must have a positive length
>
> I am not sure what I am doing wrong. When I run apply(y,1,diff) I am able to
> get output, and when I run dif.mns with just the original dataset, I am also
> able to get output.
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384129.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread Petr Savicky
On Mon, Feb 13, 2012 at 07:48:11AM -0800, syrvn wrote:
> Hello,
> 
> I use read.xls from the gdata package to read in xlsx files. Sometimes these
> data.frames contain NA columns
> and rows only. I know how to get rid of those ones but here is the R output
> of a test data set read in with read.xls
> 
> > t1
>  A  B X D   X.1 X.2
> 1 test  1 NANA
> 2asdNA  asdasdNA
> 3  NA  asdasdNA
> 4  NANA NA
> 
> t1[1,2], t1[4,5] and t1[4,6] are NA in text form in the excel sheet. I don't
> understand why in the first column it is  while in the last two is not.
> I basically want to get rid of column 5 and 6 and row 4 as they do not
> contain any relevant information. If i do a is.na.data.frame(t1):
> 
> > is.na.data.frame(t1)
>  A BX D  X.1   X.2
> [1,] FALSE FALSE TRUE FALSE TRUE FALSE
> [2,]  TRUE FALSE TRUE FALSE TRUE FALSE
> [3,] FALSE FALSE TRUE FALSE TRUE FALSE
> [4,] FALSE FALSE TRUE FALSE TRUE FALSE
> 
> does not give me the result I hoped to get.
> 
> It seems that  and NA are treated as NA but in t1[4,6] it is treated as
> FALSE because if I do
> 
> > as.character(t1[4,6])
> [1] "NA "

Hi.

I do not know, how "NA " appeared, however, it is possible
to change them to real NA as follows.

  # some data frame
  df <- structure(list(a = c(NA, 2L, 3L, 4L), b = c("a", NA, "c", "NA "),
c = structure(c(1L, 2L, NA, 4L), .Label = c("e", "f", "g", "h"),
class = "factor")), .Names = c("a", "b", "c"), row.names = c(NA, -4L),
class = "data.frame")
  df

 abc
  1 NAae
  2  2 f
  3  3c 
  4  4  NA h

  df[4, 2] # this is not NA, but "NA "

  [1] "NA "

  # replace all "NA " by NA in column 2

  df[which(df[,2] == "NA "), 2] <- NA
  df

 abc
  1 NAae
  2  2 f
  3  3c 
  4  4 h

Hope this helps.

Petr Savicky.

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


Re: [R] How to import time-series data

2012-02-13 Thread Gabor Grothendieck
On Mon, Feb 13, 2012 at 8:23 AM, RichardSmith  wrote:
>
> Gabor Grothendieck wrote
>>
>> Try this xyplot.zoo lattice graph.   Time series are represented in
>> columns so we transpose the data and convert it to zoo.  The screen=
>> argument available in xyplot.zoo groups series into panels:
>>
>> Lines <- "plant,aphid,1,2,3,4
>> pumpkin,1-2,0.065566,0.057844,0.08,0.086879
>> pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
>> squash,1-4,0.126939,0.115003,0.140275,0.188829"
>>
>> library(zoo)
>> library(lattice)
>> DF <- read.csv(text = Lines)
>> z <- zoo(t(DF[3:6]))
>> colnames(z) <- DF$aphid
>> xyplot(z, screen = DF$plant)
>>
>
> Thank you! That gets the data in exactly the shape I was expecting. I was
> hoping to get the graph showing all lines on one plot, but coloured
> according to plant. I tried to change screen=DF$plant for groups=DF$plant,
> but it doesn't work, and I can't figure out from the documentation why it
> doesn't work (I think I need to more thoroughly understand data types
> first). Could you point me in the right direction?
>

1. Try this which uses lattice zoo graphics:

xyplot(z, screen = 1, col = DF$plant)

or with a legend:

key <- list(space = "top",  text = levels(DF$plant), points = FALSE,
lines = TRUE, col = 1:nlevels(DF$plant))
xyplot(z, screen = 1, col = DF$plant, auto.key = key)

2. or using classic zoo graphics

plot(z, screen = 1, col = DF$plant)

To add a legend:

legend("topleft", legend = levels(DF$plant), col = 1:nlevels(DF$plant), lty = 1)

-- 
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] Two surfaces in one plot with visibility

2012-02-13 Thread Sebastian Schubert
Hi!

On 13/02/12 17:15, Duncan Murdoch wrote:
>> I would like plot two surfaces which are each given by vectors x and y,
>> and a matrix m(x,y) representing the z coordinate.
[..]
>> I
>> would like to have the visibility of the surfaces taken into account as
>> if they are solid thin surfaces, so that for example the order of the
>> plot commands does not matter.

> That's really hard in persp().   You'd have to plot the facets of the
> surfaces from back to front, and there's no easy way to do that.
> I'd recommend using rgl::persp3d, where your graphics hardware will do
> the computations of which surface is in front.

Thanks a lot! Works really well and created a "wow" effect (especially
when comparing to the manual tuning of the theta and phi angles in
persp() ).

Great job!

Sebastian



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Steve Lianoglou
Sorry, this:

> options(error=utils:::dum.frames)

Should be:

options(error=utils:::dump.frames)

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Steve Lianoglou
Hi,

On Mon, Feb 13, 2012 at 10:53 AM, Martin Batholdy
 wrote:
> Ok, I am sorry,
>
> My trainingset consists of a 60 x 204 matrix (independent_training – 204 
> features).
> I have 60 continuous labels (dependent_training, ranging from 2.25 to 135).
>
> this is all the code I use:
>
> library(kernlab)
> rvm(as.matrix(independent_training), dependent_training, type="regression", 
> kernel = "vanilladot")

Can you call `traceback()` after you get the error to see if you can
follow the code path that results in the explosion?

Downloading the kernlab src package will be helpful while your smoking
out the error so you can look at the entire source code, too.

In my .Rprofile, I actually have something like so:

options(error=utils:::dum.frames)

Which allows me to call `debugger()` after an error is thrown and
drops me into the location that threw the error (most of the time (I
think)), allowing me to poke around and see who's who, and what's
what.

HTH,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Suggests/Enhances or .onLoad for S3-methods for optional package

2012-02-13 Thread Jon Olav Skoien

Hi,

I am developing a package B that, among other things, also offers some 
extra S3-methods for functions in package A if the user has installed A. 
I do not want to list A under Depends of B, as the dependency list of A 
is rather long, and most potential users of B will not be interested in 
package A. Unfortunately I struggle with doing this right. So far I have 
listed A under Suggests, and had a .onLoad function in B with
if (require(A)) registerS3methods(newMethodsMatrix, package = A, env = 
environment(B))
But starting with R 2.13 or R 2.14, R CMD check complain about this 
require call in .onLoad, referring to the "good practice"-section of 
.onAttach. I guess this could also be a problem when uploading the 
package to CRAN, so I am trying to find another solution.


So far I have tried:
List A under Suggest of B, with a conditional import in NAMESPACE.
If I build a Windows-binary from this when A is installed, this package 
can be installed but not loaded on computers where A is not installed.


List A under Enhances of B.
This seems to be the right thing, as the R extensions manual says: "the 
‘Enhances’ field lists packages “enhanced” by the package at hand, e.g., 
by providing methods for classes from these packages".
However, although it seems I can install and load package B when I 
conditionally import package A in the NAMESPACE, R CMD check stops with 
the error: Namespace dependency not required: A
If I remove the import, R CMD check is happier, but I cannot load the 
package after installing.


I have read about the use of "Suggest", "Enhances" etc in "Writing R 
Extensions", but could not figure out the right way to do this. I am 
sure there is something I am missing here.


Thanks,
Jon

--
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.sko...@jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do 
not necessarily represent official views of the European Commission.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non linear quantile regression - Median not plotting where it should

2012-02-13 Thread Roger Koenker
Dan,

It is hard to say without being able to reproduce your example.  If you send me 
the data
I could try to advise something.

Roger

url:www.econ.uiuc.edu/~rogerRoger Koenker
emailrkoen...@uiuc.eduDepartment of Economics
vox: 217-333-4558University of Illinois
fax:   217-244-6678Urbana, IL 61801

On Feb 13, 2012, at 7:50 AM, Dan Morovitz wrote:

> Hi,
> 
> 
> I'm attempting to calculate the 0.25 and 0.97 quantiles for tree height (0-50 
> meters) against tree age (0-300 years) and I am running into some difficulty 
> with the plotted grafic. I've run the examples in the quantreg help and can 
> get those to work properly and by plugging in my data I can also get the 
> lines plotted on my dataset. Unfortunately I'm running into a problem with 
> the median and other regression lines with tree age younger than 50 years, 
> basically the median is in this range overestimated and even comes out of the 
> rage of oberservations. here is the code I'm using.
> 
> 
> # then fit the median using nlrq
> 
> spruce.nlrq <- nlrq(height ~ SSlogis(age, Asym, mid, scal),data=spruce, 
> tau=0.5, trace=TRUE)
> lines(1:200, predict(spruce.nlrq, newdata=list(age=1:200)), col="2")
> 
> 
> I believe  this has something to do with the SSlogis, as this gives the 
> parameters for an S curve.  My data set does not have the typical S curve 
> shape, instead you could image it as starting at the inflection point of an S 
> curve. This is what I expect the .025 quantile to be similar to:
> 
> x <- seq(1,100,1)
> plot(log(x))
> 
> 
> the 0,975 should also have a logarithmic shape but no such a steep incline.  
> Ive tried using different self starting models as found under:
> 
> apropos("^ss")
> 
>   
> however I have not gotten them to work, or at least to fix the problem. 
> Curves similar to mine look like these site index curves:
> http://www.extension.umn.edu/distribution/naturalresources/components/3473-13.html
> 
> In the example from the nlrq help the lines of the median and the various 
> quantiles all start from the same location, tha is basically (x=0, y=0) in 
> the coodinate plane.  With my problem, the lines start to be drawn from 
> various different positions ( the lines always start at age(x)=0, but the 
> height(y) can range between 0 and 15).
> Additionally, the data set is quite large. with about 50,000 oberservations 
> on age and height.
> Does anyone have a suggestion on how to fix this problem?
> Thanks in advance
> Dan
> 
>   [[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] multi-regression with more than 50 independent variables

2012-02-13 Thread David L Carlson
You need to spend some time reading about multiple regression. In statistics
there is always what is possible and what is advisable. I'm not going to
address whether a regression of 57 independent variables is advisable, only
possible. For your data, it is not possible. The attached data contain only
13 observations so the maximum number of independent variables you can use
is 13. Consider the following example:

example <- data.frame(y=rnorm(3), x1=rnorm(3), x2=rnorm(3), x3=rnorm(3))
lm(y~x1 + x2, example)
lm(y~x1 + x2 + x3, example)

We create four variables using random normal numbers for 3 cases (rows). The
first regression (2 independent variables "works" (i.e. there are no NA's).
The second produces an NA for the third independent variable. In my example,
the three random variables are not correlated with one another. In your data
there must be correlations among the 57 variables so that you are only
getting slope values for 11.

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of R DF
Sent: Monday, February 13, 2012 9:19 AM
To: r-help@r-project.org
Subject: [R] multi-regression with more than 50 independent variables

Hi R Users,

I am going to run a multiple linear regression with around 57 independent
variables. Each time I run the model with just 11 variables, the results
are reasonable. With increasing the number of independent variables more
than 11, the coefficients will get "NA" in the output.  Is there any
limitation for the number of independent variables in multiple linear
regressions in R? I attached my dataset as well as R codes below:



mlr.data<- read.table("./multiple.txt",header=T)

mlr.output<- lm(formula = CaV ~ SHG +  TrD+  CrH+ SPAD+ FlN+ FrN+   YT+
LA+ LDMP+B+Cu+  Zn+   Mn +   Fe+   K +  P+   N +Clay30 +Silt30 +Sand30
+Clay60 +Silt60 +Sand60 +ESP30 +NaEx30+ CEC30+Cl30+ SAR30 +KSol30+ NaSol30
+CaMgSol3 +ZnAv30 +FeAv30 +OC30 +PAv30 +KAv30 +TNV30+ pH30+ EC30 +SP30
+ESP60 +NaEx60 +CEC60  +Cl60 +SAR60 +KSol60 +NaSol60 +CaMgSol6
+ZnAv60+FeAv60 +OC60 +PAv60 +KAv60 +TNV60 +pH60 + EC60 +SP60, data=mlr.data)

summary (mlr.output)




Regards,

Reza

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


Re: [R] how to plot a nice legend?

2012-02-13 Thread William Stockhausen
Jonas,

A relatively simple way to get the legend to plot beside a graph is to use
the "layout" function to create two plot areas, create the graph in the
first area and the legend in the second area.  You can fool around with the
location of the legend by changing the parameters to "layout":

layout(matrix(c(1,2,1,3),nrow=2,ncol=2,byrow=TRUE),widths=c(8,4),heights=c(5,10));
plot(1:10,1:10,lty=1); #main graph
plot(c(0,1),c(0,1),type='n',bty='n',ann=FALSE,xaxt='n',yaxt='n');
legend('topleft',c('txt 1','txt 2'),pch=c(21,22));
Note that you can use 'layout.show(n=3)' (no quotes, of course) after
calling "layout" above to let you see the 3 plot areas (you only use the
1st two in the example above).  You can spcify the plot widths/heights in
absolute units in "layout" using lcm().

Hope this helps.

Buck Stockhausen
***
* Dr. William T. Stockhausen  *
***
* Resource Ecology and Fisheries Management   *
* Alaska Fisheries Science Center *
* National Marine Fisheries Service   *
* National Oceanic and Atmospheric Administration *
* 7600 Sand Point Way N.E.*
* Seattle, Washington 98115-6349  *
***
* email: william.stockhau...@noaa.gov *
* voice: 206-526-4241 fax: 206-526-6723   *
* web  : http://www.afsc.noaa.gov *
***
All models are wrong, some are useful.--G.E.P. Box
Beware of geeks bearing equations.--W. Buffett
***
Disclaimer: The opinions expressed above are personal
and do not necessarily reflect official NOAA policy.




On Sun, Feb 12, 2012 at 4:07 PM, Duncan Murdoch wrote:

> On 12-02-11 9:07 PM, Jonas Stein wrote:
>
>> Wrong? Nothing. You told R to put the legend at c(1,3)
>>> so it did. If you want it elsewhere you need to specify that.
>>> legend(-1,3, legend=c("one", "two"), inset=-1, xpd=NA)
>>> maybe, or some other location?
>>>
>>
>> ok that works fine. Now i understand how to use it.
>> If i create several plots it would be nice if all legends would
>> have the same distance to plots with different scaling.
>>
>> Can the legend be placed vertically centered, 1cm right to the plot aera?
>>
>
> I'm not sure what position you mean, but legend("top", ...) puts it on the
> top edge of the plot, and the inset argument gives detailed positioning.
>  The units aren't cm, but the grDevices package (or is it grid?) has
> functions to convert between units.
>
> Duncan Murdoch
>
>
>
>>  Can i include a legend like this in a standard plot like
 plot(1:10) too?
 http://www.r-bloggers.com/wp-**content/uploads/2011/03/**heatmap.png

>>>
>>> Yes.
>>>
>>> What part of that do you want to duplicate?
>>>
>>
>> The coloured squares.
>> for the reader who got to this article and had the same question:
>> I have just found another nice solution for a colour legend a minute ago
>> http://www.r-bloggers.com/**rethinking-loess-for-binomial-**
>> response-pitch-fx-strike-zone-**maps/
>>
>> You can specify colors, symbols, labels, etc. in legend().
>>>
>>
>> can i even invent my own symbols?
>>
>> Also, please link to the original blog post, not just the figure, so that
>>> the author gets some credit and we can see the code used.
>>>
>>
>> sure
>> http://www.r-bloggers.com/**ggheat-a-ggplot2-style-**heatmap-function/
>>
>> kind regards,
>>
>>
>  __**
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Two surfaces in one plot with visibility

2012-02-13 Thread Duncan Murdoch

On 13/02/2012 9:24 AM, Sebastian Schubert wrote:

Hi,

I would like plot two surfaces which are each given by vectors x and y,
and a matrix m(x,y) representing the z coordinate. With persp() I can
plot both, using par(new=TRUE) I can put it in one plot. However, I
would like to have the visibility of the surfaces taken into account as
if they are solid thin surfaces, so that for example the order of the
plot commands does not matter.

Any idea how to do that?


That's really hard in persp().   You'd have to plot the facets of the 
surfaces from back to front, and there's no easy way to do that.
I'd recommend using rgl::persp3d, where your graphics hardware will do 
the computations of which surface is in front.


Duncan Murdoch

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


Re: [R] Writing output into a file

2012-02-13 Thread Suranga Kasthurirathne
Hi,

many thanks for the reply. I really appreciate it.
Since I'm still very new to R, I think I should take some time to research
what you suggested.
(I don't want to keep posting basic questions to the list all the time)

But still, thank you so much for being helpful...



On Mon, Feb 13, 2012 at 7:23 PM, Rui Barradas  wrote:

> Hello,
>
> > I tried writing this data into a file using the save(myList,
> > file="test1.bin") command, but unfortunately, the numerical values seem
> > to get garbled when I do so.
> >
> > The numbers in my RGui look like
> >
> > 0, 0.5, 0, 1 etc. etc.
> >
> > But when I stored it into a .bin file, and retrieved it using java code,
> > it returns data such as,
> >
>
> The problem should be in the use of java, 'save' uses a R format , RDA.
> You can use 'ascii=TRUE'and see it with a text editor. Also see
>
> ?save
>
> > I also tried the second method (using a # Open a file connection)
> >
> > Unfortunately, here too the data gets extremely garbled.
>
> Don't understand why, check the output file with a text editor and let us
> know
> what is wrong.
>
> The problem I've seen is that the use of 'strsplit' coerses the numeric
> data
> to character,
> but this is easy to solve.
>
> Does your list have sub-lists?
>
> Rui Barradas
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4383741.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.
>



-- 
Best Regards,

Suranga

[[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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy
Ok, I am sorry,

My trainingset consists of a 60 x 204 matrix (independent_training – 204 
features).
I have 60 continuous labels (dependent_training, ranging from 2.25 to 135).

this is all the code I use:

library(kernlab)
rvm(as.matrix(independent_training), dependent_training, type="regression", 
kernel = "vanilladot")



On 13.02.2012, at 16:40, David Winsemius wrote:

> 
> On Feb 13, 2012, at 10:23 AM, Martin Batholdy wrote:
> 
>> Hi,
>> 
>> For another trainingset I get this error message, which again is rather 
>> cryptic to me:
>> 
> Just imagine how it seems to us!
> 
>> Setting default kernel parameters
>> 
>> Error in array(0, c(n, p)) : 'dim' specifies too large an array
>> RMate stopped at line 0 of selection
>> Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array
> 
> You are on you way to the prize for the greatest number of cryptic (your 
> word) postings in a short interval. (And this one doesn't even have the 
> context of your posting of 8 minutes ago.)
> 
>> thanks for any suggestions!
> 
> More details about data and code.
> 
> -- 
> 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.


[R] Deleting rows and columns containing NA's and "" only

2012-02-13 Thread syrvn
Hello,

I use read.xls from the gdata package to read in xlsx files. Sometimes these
data.frames contain NA columns
and rows only. I know how to get rid of those ones but here is the R output
of a test data set read in with read.xls

> t1
 A  B X D   X.1 X.2
1 test  1 NANA
2asdNA  asdasdNA
3  NA  asdasdNA
4  NANA NA

t1[1,2], t1[4,5] and t1[4,6] are NA in text form in the excel sheet. I don't
understand why in the first column it is  while in the last two is not.
I basically want to get rid of column 5 and 6 and row 4 as they do not
contain any relevant information. If i do a is.na.data.frame(t1):

> is.na.data.frame(t1)
 A BX D  X.1   X.2
[1,] FALSE FALSE TRUE FALSE TRUE FALSE
[2,]  TRUE FALSE TRUE FALSE TRUE FALSE
[3,] FALSE FALSE TRUE FALSE TRUE FALSE
[4,] FALSE FALSE TRUE FALSE TRUE FALSE

does not give me the result I hoped to get.

It seems that  and NA are treated as NA but in t1[4,6] it is treated as
FALSE because if I do

> as.character(t1[4,6])
[1] "NA "

one can see that there is a whitespace after NA which is, however, not in
the excel sheet for sure.

I do not know how to deal with that...

Cheers

--
View this message in context: 
http://r.789695.n4.nabble.com/Deleting-rows-and-columns-containing-NA-s-and-only-tp4384173p4384173.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] MCMCglmm with cross-classified random effects

2012-02-13 Thread Agostino Moro
Dear R-users,

I would like to fit  a glmm with cross-classified random effects with
the function MCMCglmm. Something along the lines:

model1<-MCMCglmm(response~pred1, random=~re1+re2, data=data)

where re1 and re2 should be crossed random effects. I was wondering
whether you could tell me specifying cross-classified random effects
in MCMCglmm requires a particular syntax? Are there any examples
somewhere? I have had a look at the manual and the package vignette,
but I have not been able to find any examples relevant to what I want
to do.

Thanks,

Agostino

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Two surfaces in one plot with visibility

2012-02-13 Thread Sebastian Schubert
Hi,

I would like plot two surfaces which are each given by vectors x and y,
and a matrix m(x,y) representing the z coordinate. With persp() I can
plot both, using par(new=TRUE) I can put it in one plot. However, I
would like to have the visibility of the surfaces taken into account as
if they are solid thin surfaces, so that for example the order of the
plot commands does not matter.

Any idea how to do that?

Thanks a lot,

Sebastian



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non linear quantile regression - Median not plotting where it should

2012-02-13 Thread Dan Morovitz
Hi,


I'm attempting to calculate the 0.25 and 0.97 quantiles for tree height (0-50 
meters) against tree age (0-300 years) and I am running into some difficulty 
with the plotted grafic. I've run the examples in the quantreg help and can get 
those to work properly and by plugging in my data I can also get the lines 
plotted on my dataset. Unfortunately I'm running into a problem with the median 
and other regression lines with tree age younger than 50 years, basically the 
median is in this range overestimated and even comes out of the rage of 
oberservations. here is the code I'm using.


# then fit the median using nlrq

spruce.nlrq <- nlrq(height ~ SSlogis(age, Asym, mid, scal),data=spruce, 
tau=0.5, trace=TRUE)
lines(1:200, predict(spruce.nlrq, newdata=list(age=1:200)), col="2")


I believe  this has something to do with the SSlogis, as this gives the 
parameters for an S curve.  My data set does not have the typical S curve 
shape, instead you could image it as starting at the inflection point of an S 
curve. This is what I expect the .025 quantile to be similar to:

x <- seq(1,100,1)
plot(log(x))


the 0,975 should also have a logarithmic shape but no such a steep incline.  
Ive tried using different self starting models as found under:

apropos("^ss")

      
however I have not gotten them to work, or at least to fix the problem. Curves 
similar to mine look like these site index curves:
http://www.extension.umn.edu/distribution/naturalresources/components/3473-13.html

In the example from the nlrq help the lines of the median and the various 
quantiles all start from the same location, tha is basically (x=0, y=0) in the 
coodinate plane.  With my problem, the lines start to be drawn from various 
different positions ( the lines always start at age(x)=0, but the height(y) can 
range between 0 and 15).
Additionally, the data set is quite large. with about 50,000 oberservations on 
age and height.
Does anyone have a suggestion on how to fix this problem?
Thanks in advance
Dan

[[alternative HTML version deleted]]

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


Re: [R] How to import time-series data

2012-02-13 Thread RichardSmith

Gabor Grothendieck wrote
> 
> Try this xyplot.zoo lattice graph.   Time series are represented in
> columns so we transpose the data and convert it to zoo.  The screen=
> argument available in xyplot.zoo groups series into panels:
> 
> Lines <- "plant,aphid,1,2,3,4
> pumpkin,1-2,0.065566,0.057844,0.08,0.086879
> pumpkin,1-3,0.107612,0.097272,0.11663,0.160499
> squash,1-4,0.126939,0.115003,0.140275,0.188829"
> 
> library(zoo)
> library(lattice)
> DF <- read.csv(text = Lines)
> z <- zoo(t(DF[3:6]))
> colnames(z) <- DF$aphid
> xyplot(z, screen = DF$plant)
> 

Thank you! That gets the data in exactly the shape I was expecting. I was
hoping to get the graph showing all lines on one plot, but coloured
according to plant. I tried to change screen=DF$plant for groups=DF$plant,
but it doesn't work, and I can't figure out from the documentation why it
doesn't work (I think I need to more thoroughly understand data types
first). Could you point me in the right direction?

Thanks so much for your help so far.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-import-time-series-data-tp4381372p4383740.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] logical operator for different dimensions

2012-02-13 Thread uday
Hi  Petr,

You were correct ,  thats was the mistake . I am sorry for last reply. now
its working. 


Cheers 
Uday  

--
View this message in context: 
http://r.789695.n4.nabble.com/logical-operator-for-different-dimensions-tp4383316p4384143.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] Writing output into a file

2012-02-13 Thread Rui Barradas
Hello,

> I tried writing this data into a file using the save(myList,
> file="test1.bin") command, but unfortunately, the numerical values seem
> to get garbled when I do so.
>
> The numbers in my RGui look like
>
> 0, 0.5, 0, 1 etc. etc.
>
> But when I stored it into a .bin file, and retrieved it using java code,
> it returns data such as,
>

The problem should be in the use of java, 'save' uses a R format , RDA.
You can use 'ascii=TRUE'and see it with a text editor. Also see

?save

> I also tried the second method (using a # Open a file connection)
>
> Unfortunately, here too the data gets extremely garbled.

Don't understand why, check the output file with a text editor and let us
know
what is wrong.

The problem I've seen is that the use of 'strsplit' coerses the numeric data
to character,
but this is easy to solve.

Does your list have sub-lists?

Rui Barradas

--
View this message in context: 
http://r.789695.n4.nabble.com/Writing-output-into-a-file-tp4382243p4383741.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] Error in apply(x2, 1, diff) : dim(X) must have a positive length

2012-02-13 Thread hithit168
Thank you for your help, David. I was trying to run bootrapping on the
dataset "shoes" from MASS package. But I still have some problem here.

> as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
A B
[1,] 13.2 14.0
[2,] 8.2 8.8
[3,] 10.9 11.2
[4,] 14.3 14.2
[5,] 10.7 11.8
[6,] 6.6 6.4
[7,] 9.5 9.8
[8,] 10.8 11.3
[9,] 8.8 9.3
[10,] 13.3 13.6
> y=as.matrix(data.frame(shoes),nrows=10,ncols=2,byrow=T)
> class(y)
[1] "matrix"
> apply(y,1,diff)
[1] 0.8 0.6 0.3 -0.1 1.1 -0.2 0.3 0.5 0.5 0.3
> dif.mns <- function(x2,tr1=.1,tr2=.2){
+ diffs=apply(x2,1,diff) 
+ mn1=mean(diffs)
+ mn2=mean(diffs,tr=.1)
+ mn3=mean(diffs,tr=.2)
+ mn4=median(diffs)
+ mns=c(mn1,mn2,mn3,mn4) 
+ list(mnds=round(mns,3))}
> dif.mns(y,tr1=.1,tr2=.2)
$mnds
[1] 0.410 0.400 0.417 0.400

> bootstrap(y,nboot=1000,theta=dif.mns)
Error in apply(x2, 1, diff) : dim(X) must have a positive length

I am not sure what I am doing wrong. When I run apply(y,1,diff) I am able to
get output, and when I run dif.mns with just the original dataset, I am also
able to get output.



--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384129.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] Wavelet and inverse wavelet to filter data

2012-02-13 Thread bergdepp
Dear Friends of R,

I would like to filter high frequent turbulence data with wavelet analysis.
Therefore i want to calculate the wavelet coefficients of the raw data.
And then the inverse for a special frequency band.

How can i do this in the best and easiest way?

Many thanks for your answers and help,

Best regards



[[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] multi-regression with more than 50 independent variables

2012-02-13 Thread R DF
Hi R Users,

I am going to run a multiple linear regression with around 57 independent
variables. Each time I run the model with just 11 variables, the results
are reasonable. With increasing the number of independent variables more
than 11, the coefficients will get “NA” in the output.  Is there any
limitation for the number of independent variables in multiple linear
regressions in R? I attached my dataset as well as R codes below:



mlr.data<- read.table("./multiple.txt",header=T)

mlr.output<- lm(formula = CaV ~ SHG +  TrD+  CrH+ SPAD+ FlN+ FrN+   YT+
LA+ LDMP+B+Cu+  Zn+   Mn +   Fe+   K +  P+   N +Clay30 +Silt30 +Sand30
+Clay60 +Silt60 +Sand60 +ESP30 +NaEx30+ CEC30+Cl30+ SAR30 +KSol30+ NaSol30
+CaMgSol3 +ZnAv30 +FeAv30 +OC30 +PAv30 +KAv30 +TNV30+ pH30+ EC30 +SP30
+ESP60 +NaEx60 +CEC60  +Cl60 +SAR60 +KSol60 +NaSol60 +CaMgSol6
+ZnAv60+FeAv60 +OC60 +PAv60 +KAv60 +TNV60 +pH60 + EC60 +SP60, data=mlr.data)

summary (mlr.output)




Regards,

Reza
CaV SHG TrD CrH SPADFlN FrN YT  LA  LDMP
B   Cu  Zn  Mn  Fe  K   P   N   Clay30  Silt30  
Sand30  Clay60  Silt60  Sand60  ESP30   NaEx30  CEC30   Cl30SAR30   KSol30  
NaSol30 CaMgSol3ZnAv30  FeAv30  OC30PAv30   KAv30   TNV30   pH30
EC30SP30ESP60   NaEx60  CEC60   Cl60SAR60   KSol60  NaSol60 
CaMgSol6ZnAv60  FeAv60  OC60PAv60   KAv60   TNV60   pH60EC60
SP60
49.83   15.822.32   45.882.7126 5   55.834.757.7
17.98.4 14.750.5144.7   0.9 0.1 1.7 14  50  
36  10  26  64  3.2 0.3 11.987.75.6 2.5 
25.769.82.9 3.1 0.6664.4360 14.89.940.6 
39.64.8 0.2 12.251.46.9 1.4 33.469.91.8 
3.4 0.2 3.5 290 11.57.193.2140.1
37.85   18.920.89   53.275.9169 4   67.440.158.6
15.87.9 12.153.2141.6   0.7 0.1 1.9 13  51  
34  11  28  64.01.9 0.2 12.545.77.8 3.8 
22.977.93.1 2.5 0.6945.6390 14.87.2 1.1 
40.15.4 0.1 13.359.97.9 1.7 56.658.91.5 
5.5 0.6 1.9 350 10.27.1 3.7 42.1
64.12   20.719.04   43.974.3133 5   55.938.760.0
12.16.3 12.647.4159.5   1.0 0.1 1.6 12  48  
33  13  26  62.06.4 1.1 12.633.210.11.8 
43.899.31.5 2.8 0.5720.5470 15.17.1 0.7 
39.84.9 0.3 10.965.57.1 2.3 42.166.41.1 
3.9 0.7 2.9 288.9   12.27.2 4.1 35.6
90.28   14.619.52   56.961.9145 7   66.533.259.1
13.74.7 10.052.1241.1   0.8 0.1 1.9 13  47  
32  10  30  57.05.5 0.3 11.731.23.5 2.4 
50.465.71.9 2.5 0.8841.9398 14.37   2.4 
38.73.1 0.5 14.171.98.4 1.9 36.759.10.9 
2.6 0.5 2.7 290.7   13.67   2.6 43.7
111.18  13.216.53   61.378  127 6   49.941.751.6
14.74.7 10.055.8148.9   0.7 0.1 1.9 14  46  
37  11  28  60.03.9 0.7 11  21.74.3 0.9 
33.773.62.3 2.7 0.7833.4349 15.27.4 0.9 
39.12.8 0.1 12.576.68.9 3.1 32.171.40.5 
6.9 0.5 2.5 256.9   15.17.5 1.7 36.7
59.11   12.921.34   45.378.9178 6   63.339.852.0
19.54.2 8.9 54.7229.5   0.7 0.1 1.7 13  46  
36  12  30  62.02.7 0.7 12.919.52.6 2.8 
61.286.92.2 3.7 0.8627.8400.5   17.17.1 2.1 
39.93.9 0.3 11.957.46.7 1.6 30.189.91.8 
5.8 0.3 3.7 224.8   12.97.3 5.5 34.9
80.89   17.915.86   40.366.8154 7   45.636.847.8
21.63.7 12.654.7162.1   0.7 0.1 1.9 11  50  
35  13  31  61.02.9 0.4 10.937.97.1 1.9 
19.555.82.8 2.9 0.6645.1459 15.67.2 0.8 
36.15.1 0.4 13.185.55.7 2.1 29.192.11.9 
7.8 0.7 2.8 278.9   11.87.2 6.1 32.7
122.74  16.617.29   43  77.8140 6   32.937.755.6
20.04.2 12.147.4152.6   0.9 0.1 1.7 14  49  
36  11  25  58.03.2 1.5 11.524.53.9 3.7 
20.856.91.9 2.6 0.7240.7  

Re: [R] R-help Digest, Vol 108, Issue 13

2012-02-13 Thread Milan Bouchet-Valat
Le lundi 13 février 2012 à 19:48 +0800, 丁飞 a écrit :
> dear:
> i want to know how to get a survival curve of the Cox proportional risk 
> regression, thank you. 
See the relevant part of the "Survival" Task View here:
http://cran.r-project.org/web/views/Survival.html

And more specifically, see the coxph() function in the survival package.
A tutorial is available from:
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf


(But RSiteSearch("coxph") or a simple Google search will give you many
more results.)

Cheers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 10:23 AM, Martin Batholdy wrote:


Hi,

For another trainingset I get this error message, which again is  
rather cryptic to me:



Just imagine how it seems to us!


Setting default kernel parameters

Error in array(0, c(n, p)) : 'dim' specifies too large an array
RMate stopped at line 0 of selection
Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag ->  
array


You are on you way to the prize for the greatest number of cryptic  
(your word) postings in a short interval. (And this one doesn't even  
have the context of your posting of 8 minutes ago.)



thanks for any suggestions!


More details about data and code.

--
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] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy

I am using a linear kernel (vanilladot).
By switching the kernel, I actually get rid of the error message, but I would 
like to stick to the linear one ...


On 13.02.2012, at 16:23, Martin Batholdy wrote:

> Hi,
> 
> For another trainingset I get this error message, which again is rather 
> cryptic to me:
> 
> 
> Setting default kernel parameters  
> 
> Error in array(0, c(n, p)) : 'dim' specifies too large an array
> RMate stopped at line 0 of selection
> Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array
> 
> 
> 
> thanks for any suggestions!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] see NA

2012-02-13 Thread David Winsemius


On Feb 13, 2012, at 4:51 AM, Soheila Khodakarim wrote:


Dear All
I want to chose just spacial columns in R. (read table)

data1<- read.table("/home/Documents/data.txt",header=F,sep = "\t",  
as.is =F)

data.2<-data1[sub.data[,1],]


What is "sub.data"? are you migrating to R from a language where  
"sub." would be some kind of operation on data?


--
David.




The dimension of data.2 is correct but my data are transformed NA

head(data.2)

 V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
V19 V20 V21 V22 V23 V24
NANA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.1  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.2  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.3  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.4  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA
NA.5  NA NA NA NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
NA  NA  NA  NA  NA  NA



when I used as.is =T

Error in read.table("/home/Documents/data.txt",  :
 invalid numeric 'as.is' expression


I will appreciate if you help me.

Soheila

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


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.


[R] kernlab - error message: array(0, c(n, p)) : 'dim' specifies too large an array

2012-02-13 Thread Martin Batholdy
Hi,

For another trainingset I get this error message, which again is rather cryptic 
to me:


 Setting default kernel parameters  

Error in array(0, c(n, p)) : 'dim' specifies too large an array
RMate stopped at line 0 of selection
Calls: rvm ... .local -> backsolve -> as.matrix -> chol -> diag -> array



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


  1   2   >