[R] table() generating NAs when there are no NAs in the underlying data

2013-05-20 Thread James Savage
Hi all,
Just a quick question:
I want to generate a column of counts of a particular variable. The easiest way 
seems to be using table(). For reasonably small amounts of data, there seems to 
be no problem.
C - data.frame(A1 = sample(1:1000, 10, replace = TRUE), B1 = 
sample(1:1000, 10, replace = TRUE))
C$countC - table(C$A1)[C$A1]
summary(C$countC)
Min. 1st Qu.  MedianMean 3rd Qu.Max.
 65  94 101 101 108 132

However, if I'm building a table from a larger set (note that now I'm sampling 
from 1:10k, rather than 1:1k), it generates NAs, despite there being no NAs in 
the data I'm building the table from:
C - data.frame(A1 = sample(1:1, 10, replace = TRUE), B1 = 
sample(1:1, 10, replace = TRUE))
C$countC - table(C$A1)[C$A1]
summary(C$A1)
Min. 1st Qu.  MedianMean 3rd Qu.Max.
  12512500550087502   1

summary(C$countC)
Min. 1st Qu.  MedianMean 3rd Qu.Max.NA's
1.008.00   10.00   10.18   12.00   25.00   7
Note that if you cannot replicate this on your computer, try increasing the 
size of the set to sample from (setting it at 100 did the trick for a 
colleague of mine).

The problem appears not to occur if the data are not in a data-frame.
A - sample(1:1, 100, replace = TRUE)
summary(table(as.factor(A))[A])
Min. 1st Qu.  MedianMean 3rd Qu.Max.
57  94 101 101 108 144

It seems to only have thrown NAs only for the last few categories (in the case 
sampling from 100k, only 8, 9 and 10). That makes it manageable, 
but definitely not ideal.
I also posted this question to Stack Overflow, and users there have contributed 
a work-around. However, I would like to know why table() is exhibiting this 
behaviour.

Cheers, Jim



[[alternative HTML version deleted]]

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


[R] How to fit a normal inverse gaussian distribution to my data using optim

2013-05-20 Thread Poker
Dear R Help
Please forgive my lack of knowledge,.I would be very thankful for some help. 
Here is my problem:
I was using optim to estimate parameters of a model and I get this error message
Error in optim(x0, fn = riskll, method = L-BFGS-B, lower = lbs, upper = ubs, 
 :   
L-BFGS-B needs finite values of 'fn'



Below is the R code I have written.


library('GeneralizedHyperbolic')
data=read.table(file=MSCI_USA.csv,sep=',',header=T)
data=data[1:8173,]
#starting value
x0 - c(-0.011,0.146, 0.013,   0.639, 0.059,0.939,  -0.144  ,  1.187,1.601, 
 -0.001)
#lower bound and upper bound
lbs - c(-5,-5,-5,  -0.9, 0.1,   0,   -1,0.1,1.201, 
   -2)
ubs-  c( 5, 5,10,   0.9,5,  2, 0,3,  1000, 
   10)
#the likelihood function
riskll - function(data,para) {
  m0 - para[1]
  m1 - para[2]
  omega - para[3]
  tau - para[4]
  a - para[5]
  b - para[6]
  beta - para[7]
  theta - para[8]
  gamma - para[9]
  phi - para[10]
  T - nrow(data)
  ret - data[,2];
  rate - data[,3]
  exret=100*(ret+1-((rate/100)+1)^(1/365))
  
  h = rep(0,T);
  vx = rep(0,T);
  h[1] = 1*exret[1]^2
  vx[1] = (exret[1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[1])/h[1]
  for ( i in (2:T) ) {
h[i] = 
(omega+a*(abs(h[i-1]*vx[i-1])-tau*h[i-1]*vx[i-1])^theta+b*(h[i-1]^theta))^(1/theta)

vx[i] = 
(exret[i]-phi*exret[i-1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[i])/h[i]
  
  }
  
  mu = -1*beta*((gamma^0.5)/(gamma^2+beta^2)^0.5)
  delta=((gamma^1.5)/(gamma^2+beta^2)^0.5)
  alpha=gamma
  beta=beta
  param = c(mu, delta, alpha, beta)
  riskll - -1*sum(log(dnig(vx,param=param)))
  
  return(riskll)
}




#optimization
optim(x0,fn=riskll,method =L-BFGS-B,lower=lbs,upper=ubs, data = data)
[[alternative HTML version deleted]]

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


[R] How to fit a normal inverse gaussian distribution to my data using optim

2013-05-20 Thread Poker
Dear R Help
Please forgive my lack of knowledge,.I would be very thankful for some help.
Here is my problem:
I was using optim to estimate parameters of a model and I get this error message
Error in optim(x0, fn = riskll, method = L-BFGS-B, lower = lbs, upper = ubs, 
 :   
L-BFGS-B needs finite values of 'fn'



Below is the R code I have written.


library('GeneralizedHyperbolic')
data=read.table(file=MSCI_USA.csv,sep=',',header=T)
data=data[1:8173,]
#starting value
x0 - c(-0.011,0.146, 0.013,   0.639, 0.059,0.939,  -0.144  ,  1.187,1.601, 
 -0.001)
#lower bound and upper bound
lbs - c(-5,-5,-5,  -0.9, 0.1,   0,   -1,0.1,1.201, 
   -2)
ubs-  c( 5, 5,10,   0.9,5,  2, 0,3,  1000, 
   10)
#the likelihood function
riskll - function(data,para) {
  m0 - para[1]
  m1 - para[2]
  omega - para[3]
  tau - para[4]
  a - para[5]
  b - para[6]
  beta - para[7]
  theta - para[8]
  gamma - para[9]
  phi - para[10]
  T - nrow(data)
  ret - data[,2];
  rate - data[,3]
  exret=100*(ret+1-((rate/100)+1)^(1/365))
 
  h = rep(0,T);
  vx = rep(0,T);
  h[1] = 1*exret[1]^2
  vx[1] = (exret[1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[1])/h[1]
  for ( i in (2:T) ) {
h[i] = 
(omega+a*(abs(h[i-1]*vx[i-1])-tau*h[i-1]*vx[i-1])^theta+b*(h[i-1]^theta))^(1/theta)

vx[i] = 
(exret[i]-phi*exret[i-1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[i])/h[i]
  
  }
 
  mu = -1*beta*((gamma^0.5)/(gamma^2+beta^2)^0.5)
  delta=((gamma^1.5)/(gamma^2+beta^2)^0.5)
  alpha=gamma
  beta=beta
  param = c(mu, delta, alpha, beta)
  riskll - -1*sum(log(dnig(vx,param=param)))
 
  return(riskll)
}




#optimization
optim(x0,fn=riskll,method =L-BFGS-B,lower=lbs,upper=ubs, data = data)
[[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 create surface3d plot with surface data

2013-05-20 Thread Duncan Murdoch

On 13-05-20 12:17 AM, Nguyen Hoang wrote:

I'm very new to R, and I'm having trouble figuring out a 3d surface
plot of the data. I typically have something like this:






   0.1
   0.2
   0.3
   0.4
   0.5


   0.001
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0025
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0039
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0061
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0095
   40960.16
   40960.16
   40960.16
   40960.16
   40960.16


   0.0147
   40960.16
   40960.16
   40960.16
   33756.49
   25979.93


   0.023
   40960.16
   40960.16
   28130.81
   19838.51
   14891.95


   0.0358
   40960.16
   26877.74
   16258.07
   11004.66
   7898.252


   0.0558
   35941.34
   15461.96
   8752.924
   5487.987
   3601.922


   0.087
   21231.18
   8254.491
   4115.487
   2189.69
   1152.315


   0.1357
   11883.95
   3815.37
   1425.492
   464.9616
   84.35834


   0.2115
   6029.579
   1264.774
   166.2719
   0
   0


   0.3296
   2500.958
   115.8725
   0
   0
   0


   0.5138
   605.4039
   0
   0
   0
   0


   0.801
   0
   0
   0
   0
   0


   0.
   0
   0
   0
   0
   0

a first row corresponding to the values in y and a first column
corresponding to the values in x,the matrix of residual values are in
z as the following:



x1 - t(x) #transpose x

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
V1  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9 1

y1 - t(y)

   [,1]
V1  0.0010
V2  0.0010
V3  0.0039
V4  0.0061
V5  0.0095
V6  0.0147
V7  0.0230
V8  0.0358
V9  0.0558
V10 0.0870
V11 0.1357
V12 0.2115
V13 0.3296
V14 0.5138
V15 0.8010
V16 0.



z_t - t(z)

 [,1] [,2] [,3] [,4] [,5] [,6]  [,7]  [,8]
V1  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 40960.165 40960.165
V2  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 40960.165 26877.741
V3  40960.16 40960.16 40960.16 40960.16 40960.16 40960.16 28130.814 16258.071
V4  40960.16 40960.16 40960.16 40960.16 40960.16 33756.49 19838.507 11004.663
V5  40960.16 40960.16 40960.16 40960.16 40960.16 25979.93 14891.946  7898.252
V6  40960.16 40960.16 40960.16 40960.16 35282.13 20810.88 11618.426  5865.759
V7  40960.16 40960.16 40960.16 40960.16 29505.17 17131.90  9301.074  4447.296
V8  40960.16 40960.16 40960.16 40960.16 25179.81 14384.26  7581.456  3412.924
V9  40960.16 40960.16 40960.16 36868.08 21822.20 12257.56  6260.442  2634.903
V10 40960.16 40960.16 40960.16 32663.23 19142.03 10565.56  5218.556  2036.595
   [,9][,10]   [,11] [,12] [,13][,14] [,15] 
[,16]
V1  35941.3351 21231.183500 11883.95464 6029.5794 2500.9576 605.4039 0 0
V2  15461.9567  8254.491283  3815.37041 1264.7739  115.8725   0. 0 0
V3   8752.9239  4115.487198  1425.49197  166.27190.   0. 0 0
V4   5487.9866  2189.690272   464.961650.0.   0. 0 0
V5   3601.9222  1152.31452684.358340.0.   0. 0 0
V6   2406.3472   561.860696 0.00.0.   0. 0 0
V7   1606.2609   229.200968 0.00.0.   0. 0 0
V8   1054.181959.850348 0.00.0.   0. 0 0
V9668.1935 1.390629 0.00.0.   0. 0 0
V10   399.1614 0.00 0.00.0.   0. 0 0


I tried to use surface3d() and persp3d(), but the results was error.



library(rgl)
surface3d(x1,y1,z_t)

Error in rgl.surface(x = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,  :
   bad dimension for rows


What should I do?


Don't convert x and y into matrices, leave them as vectors.

Unlike persp, persp3d allows you to specify x and/or y as matrices, but 
then they need to be the same shape as z. It was complaining because it 
thought you had done that, but got the shape wrong.


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] table() generating NAs when there are no NAs in the underlying data

2013-05-20 Thread Duncan Murdoch

On 13-05-20 4:34 AM, James Savage wrote:

Hi all,
Just a quick question:
I want to generate a column of counts of a particular variable. The easiest way 
seems to be using table(). For reasonably small amounts of data, there seems to 
be no problem.
C - data.frame(A1 = sample(1:1000, 10, replace = TRUE), B1 = 
sample(1:1000, 10, replace = TRUE))
C$countC - table(C$A1)[C$A1]
summary(C$countC)
Min. 1st Qu.  MedianMean 3rd Qu.Max.
  65  94 101 101 108 132

However, if I'm building a table from a larger set (note that now I'm sampling 
from 1:10k, rather than 1:1k), it generates NAs, despite there being no NAs in 
the data I'm building the table from:
C - data.frame(A1 = sample(1:1, 10, replace = TRUE), B1 = 
sample(1:1, 10, replace = TRUE))
C$countC - table(C$A1)[C$A1]
summary(C$A1)
Min. 1st Qu.  MedianMean 3rd Qu.Max.
   12512500550087502   1

summary(C$countC)
Min. 1st Qu.  MedianMean 3rd Qu.Max.NA's
1.008.00   10.00   10.18   12.00   25.00   7
Note that if you cannot replicate this on your computer, try increasing the 
size of the set to sample from (setting it at 100 did the trick for a 
colleague of mine).

The problem appears not to occur if the data are not in a data-frame.
A - sample(1:1, 100, replace = TRUE)
summary(table(as.factor(A))[A])
Min. 1st Qu.  MedianMean 3rd Qu.Max.
57  94 101 101 108 144

It seems to only have thrown NAs only for the last few categories (in the case 
sampling from 100k, only 8, 9 and 10). That makes it manageable, 
but definitely not ideal.
I also posted this question to Stack Overflow, and users there have contributed 
a work-around. However, I would like to know why table() is exhibiting this 
behaviour.


table() isn't generating the NAs.  You're indexing the table by values 
that don't exist in it.  You don't give a completely reproducible 
example (use set.seed() if you want us to see the same random numbers 
you had), but from the look of it, your C$A1 column contains 9993 unique 
values.  You compute a table, and get a 1 dim array with 9993 entries. 
Then you index it by C$A1, which contains values larger than 9993, and 
get some NAs.


Duncan Murdoch

For example, try this:

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 relative frequency by date and operator

2013-05-20 Thread arun
Hi,
Try either:
dat2- structure(list(Operator = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c(A, D, J, L, 
M), class = factor), Score = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c(Crap, Good, 
OK, Poor),
 class = factor), Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L ), .Label = c(Apr 2013, Feb 2013, 
Jan 2013, Mar 2013, May 2013), class = factor), Freq = c(0L, 0L, 0L, 
0L, 0L, 1L, 14L, 26L, 3L, 9L, 3L, 5L, 3L, 0L, 6L, 3L, 24L, 20L, 29L, 14L, 0L, 
0L, 0L, 0L, 0L, 2L, 17L, 24L, 12L, 9L, 2L, 10L, 4L, 0L, 4L, 0L, 27L, 36L, 37L, 
13L, 0L, 0L, 0L, 0L, 0L, 15L, 16L, 20L, 5L, 15L, 3L, 6L, 17L, 3L, 5L, 5L, 31L, 
12L, 41L, 9L, 0L, 1L, 0L, 0L, 0L, 1L, 8L, 11L, 12L, 17L, 1L, 1L, 3L, 4L, 4L, 
5L, 16L, 21L, 25L, 15L, 0L, 0L, 0L, 0L, 0L, 5L, 7L, 18L, 4L, 3L, 0L, 5L, 2L, 
0L, 1L, 1L, 15L, 9L, 10L,
 9L)), .Names = c(Operator, Score, Date, Freq ), row.names = c(NA, 
-100L), class = data.frame)

dat2[,1:3]- lapply(dat2[,1:3],as.character)
res1-unsplit(lapply(split(dat2,dat2$Operator),function(x) 
{x$Rel.Freq-round(x$Freq/with(x,ave(Freq,Date,FUN=sum)),2);x}),dat2$Operator)
 subset(res1,Operator==A  Date==Jan 2013)
#   Operator Score Date Freq Rel.Freq
#41    A  Crap Jan 2013    0 0.00
#46    A  Good Jan 2013   15 0.65
#51    A    OK Jan 2013    3 0.13
#56    A  Poor Jan 2013    5 0.22
#or
dat3- dat2
dat3$Rel.Freq-round(dat3$Freq/with(dat3,ave(Freq,Operator,Date,FUN=sum)),2)
 subset(dat3,Operator==A  Date==Jan 2013)
#   Operator Score Date Freq Rel.Freq
#41    A  Crap Jan 2013    0 0.00
#46    A  Good Jan 2013   15 0.65
#51    A    OK Jan 2013    3 0.13
#56    A  Poor Jan 2013    5 0.22
 row.names(dat3)- row.names(res1)
 identical(dat3,res1)
#[1] TRUE
A.K.


I have the data frame with the following structure 

   Operator Score     Date Freq 
1          A  Crap Apr 2013    0 
2          D  Crap Apr 2013    0 
3          J  Crap Apr 2013    0 
4          L  Crap Apr 2013    0 
5          M  Crap Apr 2013    0 
6          A  Good Apr 2013    1 
7          D  Good Apr 2013   14 
8          J  Good Apr 2013   26 
9          L  Good Apr 2013    3 
10         M  Good Apr 2013    9 

I would like to aggregate this data such that I can find the 
relative frequency of each score (Good, Ok, Poor and Crap) for each 
combination of month and operator. For example For operator A in the 
month Jan 2013 - I would like the following output 

   Operator Score     Date Freq Rel.Freq 
1          A  Crap Jan 2013    0       0 
2          A  Poor Jan 2013    5      0.22 
3          A  Good Jan 2013    15  0.65 
4          A  Ok Jan 2013   3           0.13 

i.e I would like to add a relative frequency column to my 
existing data.frame. I haven't got anywhere near an automated solution. 
The closest I have is 

tmp - subset(df, Operator == A) 
tmp$N.norm - tmp$Freq/sum(ans2$Freq) 

However this sums all data for operator A regardless of date. So
 I would need to subset again according to date. Is there a 
straightforward way to do this in R 



nabble_embedstructure(list(Operator = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c(A, 
D, J, L, M), class = factor), Score = structure(c(1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 

[R] finding moving average order

2013-05-20 Thread Preetam Pal
Hi all,

I want to know the moving average order of a time series variable X_t.
I know that ar(x) works for the autoregressive order, but ma(x) is not
doing the same for moving average.I am not sure where to find the correct
function.
Any help is appreciated.

Thanks,
Preetam

-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[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] R relative frequency by date and operator

2013-05-20 Thread moadeep
I have the data frame with the following structure

   Operator Score Date Freq
1  A  Crap Apr 20130
2  D  Crap Apr 20130
3  J  Crap Apr 20130
4  L  Crap Apr 20130
5  M  Crap Apr 20130
6  A  Good Apr 20131
7  D  Good Apr 2013   14
8  J  Good Apr 2013   26
9  L  Good Apr 20133
10 M  Good Apr 20139

I would like to aggregate this data such that I can find the relative
frequency of each score (Good, Ok, Poor and Crap) for each combination of
month and operator. For example For operator A in the month Jan 2013 - I
would like the following output

   Operator Score Date Freq Rel.Freq
1  A  Crap Jan 20130   0
2  A  Poor Jan 20135  0.22
3  A  Good Jan 201315  0.65
4  A  Ok Jan 2013   3   0.13

i.e I would like to add a relative frequency column to my existing
data.frame. I haven't got anywhere near an automated solution. The closest I
have is 

tmp - subset(df, Operator == A)
tmp$N.norm - tmp$Freq/sum(ans2$Freq)

However this sums all data for operator A regardless of date. So I would
need to subset again according to date. Is there a straightforward way to do
this in R



structure(list(Operator = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c(A, 
D, J, L, M), class = factor), Score = structure(c(1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L), .Label = c(Crap, Good, OK, Poor), class = factor), 
Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L
), .Label = c(Apr 2013, Feb 2013, Jan 2013, Mar 2013, 
May 2013), class = factor), Freq = c(0L, 0L, 0L, 0L, 
0L, 1L, 14L, 26L, 3L, 9L, 3L, 5L, 3L, 0L, 6L, 3L, 24L, 20L, 
29L, 14L, 0L, 0L, 0L, 0L, 0L, 2L, 17L, 24L, 12L, 9L, 2L, 
10L, 4L, 0L, 4L, 0L, 27L, 36L, 37L, 13L, 0L, 0L, 0L, 0L, 
0L, 15L, 16L, 20L, 5L, 15L, 3L, 6L, 17L, 3L, 5L, 5L, 31L, 
12L, 41L, 9L, 0L, 1L, 0L, 0L, 0L, 1L, 8L, 11L, 12L, 17L, 
1L, 1L, 3L, 4L, 4L, 5L, 16L, 21L, 25L, 15L, 0L, 0L, 0L, 0L, 
0L, 5L, 7L, 18L, 4L, 3L, 0L, 5L, 2L, 0L, 1L, 1L, 15L, 9L, 
10L, 9L)), .Names = c(Operator, Score, Date, Freq
), row.names = c(NA, -100L), class = data.frame)



--
View this message in context: 
http://r.789695.n4.nabble.com/R-relative-frequency-by-date-and-operator-tp4667498.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] DEfining and plotting the sum of two functions

2013-05-20 Thread Honest Chipoyera
I have two functions H1(x) and H2(x) defined separately and I wish to create a 
new function H(x)  which is the sum of the two functions. I also need to plot 
the three functions using the command curve. With the aid of the example 
program below, can you please explain how I can do that in R.

H1-function(x) x^2
H2-function(x) x+5
H-function(x){H1+H2}
par(mfrow=c(3,1))
curve(H1(x),0,100)
curve(H2(x),0,100)
curve(H(x),0,100)



HW Chipoyera
Cell: 0767190507


table width=100% border=0 cellspacing=0 cellpadding=0 
style=width:100%;
tr
td align=left style=text-align:justify;font face=arial,sans-serif 
size=1 color=#99span style=font-size:11px;This communication is 
intended for the addressee only. It is confidential. If you have received this 
communication in error, please notify us immediately and destroy the original 
message. You may not copy or disseminate this communication without the 
permission of the University. Only authorised signatories are competent to 
enter into agreements on behalf of the University and recipients are thus 
advised that the content of this message may not be legally binding on the 
University and may contain the personal views and opinions of the author, which 
are not necessarily the views and opinions of The University of the 
Witwatersrand, Johannesburg. All agreements between the University and 
outsiders are subject to South African Law unless the University agrees in 
writing to the contrary. /span/font/td
/tr
/table

[[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] DEfining and plotting the sum of two functions

2013-05-20 Thread Berend Hasselman

On 20-05-2013, at 14:09, Honest Chipoyera honest.chipoy...@wits.ac.za wrote:

 I have two functions H1(x) and H2(x) defined separately and I wish to create 
 a new function H(x)  which is the sum of the two functions. I also need to 
 plot the three functions using the command curve. With the aid of the 
 example program below, can you please explain how I can do that in R.
 
 H1-function(x) x^2
 H2-function(x) x+5
 H-function(x){H1+H2}
 par(mfrow=c(3,1))
 curve(H1(x),0,100)
 curve(H2(x),0,100)
 curve(H(x),0,100)


You correctly use H1(x) and H2(x) in the curve calls.
Why don't you use H1(x)+H2(x) in function H?

H-function(x){H1(x)+H2(x)}

Berend


 
 HW Chipoyera
 Cell: 0767190507

Please post in  plain text as the Posting Guide asks you to do.

 table width=100% border=0 cellspacing=0 cellpadding=0 
 style=width:100%;
 tr
 td align=left style=text-align:justify;font face=arial,sans-serif 
 size=1 color=#99span style=font-size:11px;This communication is 
 intended for the addressee only. It is confidential. If you have received 
 this communication in error, please notify us immediately and destroy the 
 original message. You may not copy or disseminate this communication without 
 the permission of the University. Only authorised signatories are competent 
 to enter into agreements on behalf of the University and recipients are thus 
 advised that the content of this message may not be legally binding on the 
 University and may contain the personal views and opinions of the author, 
 which are not necessarily the views and opinions of The University of the 
 Witwatersrand, Johannesburg. All agreements between the University and 
 outsiders are subject to South African Law unless the University agrees in 
 writing to the contrary. /span/font/td
 /tr
 /table
 
   [[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] DEfining and plotting the sum of two functions

2013-05-20 Thread arun
Hi,
Try:
H-function(x) H1(x)+H2(x)
 H1(2)
[#1] 4
H2(2)
#[1] 7
 H(2)
#[1] 11


A.K.



- Original Message -
From: Honest Chipoyera honest.chipoy...@wits.ac.za
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Monday, May 20, 2013 8:09 AM
Subject: [R] DEfining and plotting the sum of two functions

I have two functions H1(x) and H2(x) defined separately and I wish to create a 
new function H(x)  which is the sum of the two functions. I also need to plot 
the three functions using the command curve. With the aid of the example 
program below, can you please explain how I can do that in R.

H1-function(x) x^2
H2-function(x) x+5
H-function(x){H1+H2}
par(mfrow=c(3,1))
curve(H1(x),0,100)
curve(H2(x),0,100)
curve(H(x),0,100)



HW Chipoyera
Cell: 0767190507


table width=100% border=0 cellspacing=0 cellpadding=0 
style=width:100%;
tr
td align=left style=text-align:justify;font face=arial,sans-serif 
size=1 color=#99span style=font-size:11px;This communication is 
intended for the addressee only. It is confidential. If you have received this 
communication in error, please notify us immediately and destroy the original 
message. You may not copy or disseminate this communication without the 
permission of the University. Only authorised signatories are competent to 
enter into agreements on behalf of the University and recipients are thus 
advised that the content of this message may not be legally binding on the 
University and may contain the personal views and opinions of the author, which 
are not necessarily the views and opinions of The University of the 
Witwatersrand, Johannesburg. All agreements between the University and 
outsiders are subject to South African Law unless the University agrees in 
writing to the contrary. /span/font/td
/tr
/table

    [[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] Extract t-statistics from mer object

2013-05-20 Thread arun
Hi,

Check this link
https://stat.ethz.ch/pipermail/r-help/2008-May/163274.html
A.K.


i have a mer object named model : 
S4 object of class structure(mer, package = lme4)
I want to extract  t statistics of the coeeficients from model. 
Please help me out 

package used lme4

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] x and y lengths differ

2013-05-20 Thread PIKAL Petr
Hi

Over of what Don adviced, do not use HTML posting. Your data could be scrambled 
and can not be coppied easily without user intervention.

temp-structure(list(RGE01 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 1.47, 3.11, 2.87, 2.69, 1.98, 2.22, 1.93, 1, 0.61, 0.57, 0.55, 1, 1.41, 
0.98, 2.32, 1.86, 1.81, 1.48, 2.18, 2.29, 2.31, 2.28, 1.72, 1.8, 1.71, 1.59, 
1.11, 1.24, 1.1, 1.83, 0.43, 0.98, 0.71, 1.09, 0.79, 1.11, 0.55, 0.44, 0.36, 
0.5, 0.5, 0.51, 0.48, 0.42, 0.44, 0.44), RGE02 = c(NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.97, 
0.94, 1.95, 1.95, 1.92, 1.14, 1.84, 1.45, 1.63, 1.81, 1.24, 1.29, 1.31, 1.41, 
1.2, 2.04, 2.23, 2.44, 2.11, 2.24, 0.93, 1.89, 1.93, 1.58, 2.36, 2.07, 1.79, 
1.4, 1.05, 2.14, 2.14, 2.65, 3.47, 2.93, 1.5!
 2), RGE03 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, 1.62, 0.83, 0.81, 0.84, 0.83, 1.06, 0.13, 0.72, 0.98, 0.54, 
0.8, 0.6, 0.44, 0.59, 0.78, 0.62, 0.7, 0.98, 0.68, 0.58, 0.5, 0.45, 0.37, 0.26, 
0.44, 0.6, 0.48, 0.55, 0.88, 0.4, 0.4, 0.45, 0.46, 0.52, 0.46, 0.36, 0.43, 
0.36, 0.29, 0.36, 0.64, 0.49, 0.92, 0.9, 0.54, 0.7, 0.84, 0.52, 0.81, 0.95, 
0.8, 0.64, 0.84, 0.6, 0.78, 0.76, 0.88, 0.74, 0.9), RGE04 = c(NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 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.29, 2.4, 1.74, 1.56, 2.06, 1.11, 1.63, 1.83, 1.41, 
1.37, 1.34, 1.18, 0.92, 1.64, 1.21, 1.5, 1.12, 0.7, 1.05, 1.19, 1.17, 0.68, 
0.62, 0.97, 0.71, 0.73, 0.92, 0.64, 0.48, 0.45, 0.96, 0.84, 0.97, 0.33, 0.26, 
0.31, 0.6, 0.71, 0.5, 0.46, 0.24, 0.26, 0.65, 0.85!
 , 0.9, 0.27, 0.3, 0.86, 0.82, 0.6), RGE05 = c(NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 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.36, 2.65, 
1.78, 1.29, 1.08, 1.9, 2.33, 1.72, 1.45, 0.32, 1.42, 1.06, 1.46, 1.61, 1.24, 
1.56, 1.58, 1.66, 1.49, 0.55, 1.58, 1.96, 1.26, 0.82, 0.92, 0.84, 0.72, 0.72, 
0.68, 0.98, 0.5, 0.84, 0.4, 0.3, 1.22, 0.74, 0.97, 0.52, 0.88, 0.63, 0.58, 
0.56, 0.62, 0.47, 0.46, 0.72, 1.2, 1.01, 0.88, 0.87, 1.58, 0.82, 0.67, 1.27, 
0.96, 0.54, 0.48, 1.14), RGE06 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 2.37, 2.32, 1.39, 1.2, 0.97, 1.01, 0.83, 0.86, 0.74, 0.65, 1.04, 0.79, 
0.52, 0.54, 0.57, 0.45, 0.44, 0.42, 0.47, 0.75, 0.86, 0.61, 0.79, 0.73, 0.53, 
0.61, 0.55, 0.63, 0.7, 0.62, 0.64, 0.64, 0.58, 0.5, 0.46, 0.65, 0.76, 0.44, 
0.81, 0.88, 0.48, 0.38, 0.4, 0.57, 0.39, 0.45, 0.41, 0.44, 0.6, 0.37, 0.2, 
0.23, 0.49, 0.31, 0.24, 0.38, 0.37, 0.4, 0.48, 0.46, 0.39, 0.26, 0.4, 0.38, 
0.52, 0.51, 0.78, 0.68, 0.52, 0.51, 0.5, 0.28, 0.27, 0.42, 0.4, 0.4!
 1, 0.46, 0.52, 0.53, 0.33, 0.3, 0.48, 0.48, 0.43, 0.34, 0.36, 0.28, 0.28), 
RGE07 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 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.82, 1.47, 1.37, 1.06, 
1.01, 0.72, 1.3, 1.16, 0.72, 0.88, 1.02, 0.92, 0.8, 0.89, 0.94, 1, 0.78, 0.89, 
1.08, 0.83, 0.99, 0.97, 0.82, 0.9, 0.82, 0.7, 0.87, 0.43, 0.65, 0.55, 0.49, 
0.59, 0.63, 0.38, 0.31, 0.64, 0.38, 0.48, 0.47, 0.72, 0.53, 0.46, 0.48, 0.56, 
0.56, 0.67, 0.5, 0.7, 0.63 ), RGE08 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, 1.03, 1.24, 1.2, 0.34, 0.79, 0.79, 0.72, 1.28, 0.62, 0.94, 
0.9, 0.74, 0.96, 1.07, 1.18, 1.28, 1.64, 1.18, 0.98, 0.69, 0.64, 0.74, 0.31, 
0.53, 0.26, 0.74, 0.94, 0.64, 0.6, 0.36, 0.31, 0.89, 1.05, 1.21, 1.36, 1.52, 
1.94, 0.79, 0.68, 0.98, 0.58, 0.64, 1.22, 1.09, 0.82, 0.76, 1.22, 1.16, 0.58, 
0.6, 0.74, 0.67, 0.92, 0.96, 0.9, 0.82, 0.9, 0.76, !
 1.39, 0.75, 0.93, 0.88, 0.65, 1, 1.01, 0.74, 0.87, 0.86, 0.6, 0.96, 1.
0
+ 4, 1.55, 1.2, 0.96, 0.58, 0.54, 0.48, 1.08, 0.85, 0.73, 0.68, 0.3, 0.57, 
0.83, 0.43), RGE09 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
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, 1.3, 0.67, 0.72, 0.88, 0.76, 0.79, 0.78, 0.67, 0.42, 0.35, 
0.26, 0.49, 0.68, 1.12, 0.85, 0.96, 0.5, 0.98, 0.66, 0.81, 1, 0.72, 0.78, 1.17, 
1.22, 0.78, 1.54, 2.01, 0.99, 0.96, 0.7, 0.62, 0.65, 0.53, 0.61, 1.06, 0.79, 
1.29, 0.61, 0.23, 0.32, 0.45, 0.5, 0.23, 0.37, 0.4, 0.45, 0.71, 0.56, 0.44, 
0.58, 0.54, 0.56, 0.35, 0.52, 0.44, 0.41, 0.31, 0.37, 0.39, 0.24),

Error: unexpected numeric constant in:
 0.64, 0.6, 0.36, 0.31, 0.89, 1.05, 

Re: [R] Extract t-statistics from mer object

2013-05-20 Thread Ben Bolker
arun smartpink111 at yahoo.com writes:

 
 Hi,
 
 Check this link
 https://stat.ethz.ch/pipermail/r-help/2008-May/163274.html
 A.K.
 
 i have a mer object named model : 
 S4 object of class structure(mer, package = lme4)
 I want to extract  t statistics of the coeeficients from model. 
 Please help me out 
 
 package used lme4
 

  You should also be able to use coef(summary(model)) to get
a numeric matrix representing the coefficient table, and

coef(summary(model))[,t value]

to get the t statistics.

Questions relating to nlme/lme4/glmmADMB/MCMCglmm/etc. are
best asked on the r-sig-mixed-mod...@r-project.org list ...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Loading intraday data with zoo

2013-05-20 Thread arun
Hi,
You may need to add dec=, in the read.csv.
dat1- read.table(text=
Time;Mid
31/01/2013 00:00;1,35679
31/01/2013 00:01;1,35678
31/01/2013 00:02;1,356785
31/01/2013 00:03;1,35689
31/01/2013 00:04;1,3569
31/01/2013 00:05;1,3569
31/01/2013 00:06;1,356885
31/01/2013 00:07;1,35691
31/01/2013 00:08;1,357 
,sep=;,dec=,,header=TRUE,stringsAsFactors=FALSE)

f1 - function(...) as.POSIXct(paste(...), format = %d/%m/%Y %H:%M) 
library(zoo)
 b - read.zoo(dat1, index = 1, FUN  = f1) 

library(xts)
dat2- xts(b)
 dat2
#   x
#2013-01-31 00:00:00 1.356790
#2013-01-31 00:01:00 1.356780
#2013-01-31 00:02:00 1.356785
#2013-01-31 00:03:00 1.356890
#2013-01-31 00:04:00 1.356900
#2013-01-31 00:05:00 1.356900
#2013-01-31 00:06:00 1.356885
#2013-01-31 00:07:00 1.356910
#2013-01-31 00:08:00 1.357000
 plot(dat2)
A.K.



Hi all, 

I would like to do some time series analysis on intraday data. 
Therefore, I try to read some data with zoo and then convert them a 
xts-object. 

The data are like: 
Time;Mid 
31/01/2013 00:00;1,35679 
31/01/2013 00:01;1,35678 
31/01/2013 00:02;1,356785 
31/01/2013 00:03;1,35689 
31/01/2013 00:04;1,3569 
31/01/2013 00:05;1,3569 
31/01/2013 00:06;1,356885 
31/01/2013 00:07;1,35691 
31/01/2013 00:08;1,357 

My r-code is 
df-read.csv(file.csv, header=TRUE, sep=;) 
f1 - function(...) as.POSIXct(paste(...), format = %d/%m/%Y %H:%M) 
 b - read.zoo(df, index = 1, sep=;, header = TRUE, FUN  = f1) 
data-xts(b) 
plot(data) 

The following error occurs: 
Error in plot.window(...) : need finite 'ylim' values 
In addition: Warning messages: 
1: In as.double.xts(y) : NAs introduced by coercion 
2: In min(x) : no non-missing arguments to min; returning Inf 
3: In max(x) : no non-missing arguments to max; returning -Inf 

I think the problem is that the index does not recognize the 
%d/%m/%Y %H:%M format, but I do not know how to handle this problem. 
Does anyone know a solution to my problem? 
Thank you a lot! 
Michi 


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


[R] Neural network: Amore adaptative vs batch why the results are so different?

2013-05-20 Thread xiaoyan yu
I am using the iris example came with nnet package to test AMORE. I can see
the outcomes are similar to nnet with adaptative gradient descent. However,
when I changed the method in the newff to the batch gradient descent, even
by setting the epoch numbers very large, I still found all the iris
expected class=2 being classified as class=3. In addition, all those
records in the outcomes (y) are the three digits, 0, 0.4677313, and
0.5111955. The script is as below. Please help to understand this behavior.


library('AMORE')
ir - rbind(iris3[,,1], iris3[,,2], iris3[,,3])
targets - matrix(c(rep(c(1,0,0),50), rep(c(0,1,0),50), rep(c(0,0,1),50)),
150, 3, byrow=TRUE)
samp - c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
net - newff(n.neurons=c(4, 2, 3), # number of units per layer
 learning.rate.global=1e-2,# learning rate at which
every neuron is trained
 momentum.global=5e-4,  # momentum for every
neuron
 error.criterium=LMS,# error criterium: least
mean squares
 hidden.layer=sigmoid,# activation function
of the hidden layer neurons
 output.layer=sigmoid,   # activation function of
the output layer neurons
 method=BATCHgdwm)   # training method:
adaptative or batch
nnfit - train(net,   # network to train
ir[samp,],  # input training samples
targets[samp,],   # output training samples
error.criterium=LMS, # error criterium
report=TRUE,   # provide information
during training
n.show=10,  # number of times to
report
show.step=4)
y-sim(nnfit$net,ir[samp,])

Thanks,
Xiaoyan

[[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] bar plot with non-zero starting level

2013-05-20 Thread Xianwen Chen

Hi Jim,

Thank you for the suggestion. I think overlapped rectangles will well 
present the message. I'm now trying ggplot2.


Here is the code:

require(ggplot2)
rect_MNL_Delta - data.frame(
xmin - c(1, 3, 5, 7, 9, 11, 13),
xmax - xmin + 1,
ymin - c(16.7026, 14.9968, 16.0630, 17.7510, -5.01694, 
-.44146, 1.45884),
ymax - c(21.1602, 18.7613, 19.1367, 23.6730, 2.26564, 3.08630, 
3.39865)

)
rect_GMNL - data - data.frame(
xmin - c(1, 3, 5, 7, 9, 11, 13),
xmax - xmin + 1,
ymin - c(17.20, 16.32, 15.86, 18.12, -8.86, -0.03, 0.95),
ymax - c(20.12, 18.60, 18.14, 22.29, 3.03, 3.57, 2.81)
)

ggplot() +
geom_rect(data = rect_MNL_Delta, aes(xmin = xmin, xmax = xmax, 
ymin = ymin, ymax = ymax), fill = blue, alpha = 0.1) +
geom_rect(data = rect_GMNL, aes(xmin = xmin, xmax = xmax, ymin 
= ymin, ymax = ymax), fill = green, alpha = 0.1)


The problem is that the second geom_rect() fully covered the first 
geom_rect(), instead of overlapping. Another issue is that I don't know 
how to set labels on x-axis, instead of the current ticks. I would like 
to have for instance 'Farmed cod' under the first rectangle.


Can you provide me some hints? Thank you.

Kind regards,

Xianwen

Jim Lemon wrote:

On 05/19/2013 09:19 AM, Xianwen Chen wrote:

Hi,

I want to plot grouped bars to compare 95% confidence interval estimates
from two models. Each bar represents a 95% confidence interval estimate
of a coefficient from one of the two models. Each group represents
confidence interval estimates of the same coefficient from the two 
models.


I think such a bar plot will nicely present whether 95% confidence
interval estimates of the same coefficient from the two models overlap.
All these confidence intervals do not start from the x axis.

I searched bar plot examples on Google. I found methods to plot bars in
groups by barplot(). I could only specify one offset for all confidence
interval estimates of the same model. I could not individually specify
an offset for each confidence interval estimate. Can someone please help
me on how I may proceed with individual offset for each of the bar in
the plot?


Hi Xianwen,
It seems that you want to line up either one or both of the estimates 
for each coefficient and then display the confidence intervals as bars 
around the estimates. If so, your ordinate (y-axis) won't be very 
interpretable unless you add one for each pair of coefficients. What I 
would initially suggest is that you display the coefficient values 
along a horizontal line and use error bars to show the confidence 
intervals. Here is an example:


coef-c(3.6,3.2,5.7,6.0,1.2,1.3)
CIs-c(1.2,1.4,2.7,2.6,3.1,2.9)
plot(0,xlim=c(0.5,3.5),ylim=range(c(-CIs,CIs)),type=n,
 xlab=Coefficients,ylab=95% confidence intervals,xaxt=n)
axis(1,at=c(0.8,1.2,1.8,2.2,2.8,3.2),
 labels=c(A1,A2,B1,B2,C1,C2))
abline(h=0)
library(plotrix)
dispersion(c(0.8,1.2,1.8,2.2,2.8,3.2),rep(0,6),ulim=CIs,interval=TRUE)
boxed.labels(c(0.8,1.2,1.8,2.2,2.8,3.2),0,coef)

Jim


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


Re: [R] Generate positive definite matrix with constraints

2013-05-20 Thread mary

Thank you but I want to create a matrix (4,4) or (8,8) not just only a (2,2)
matrix... 



--
View this message in context: 
http://r.789695.n4.nabble.com/Generate-positive-definite-matrix-with-constraints-tp4667449p4667509.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] Gamma curve fit to data with specific bins

2013-05-20 Thread Lorentz, Andrew
Good afternoon,

I have some rainfall drop size data (frequency count within drop size) that is 
already arranged into specific bins (Size). I am looking to fit a gamma curve 
onto a histogram of the data.

At the moment I have been able to create estimate the gamma parameters from the 
PDF of the frequencies. And plot the points on the gamma curve.  However, the 
x-axis is only a count and not the specific drop size values.  Nor have I been 
able to plot the histogram and the curve together.

Could you advise? Many thanks.

Code:
# Load the probability data from the Drop Size Distribution
PDF=c(0.0941,0.2372,0.2923,0.1750,0.0863,0.0419,0.0207,0.0128,0.0142,0.0071,0.0041,0.0031,0.0032,0.0057,0.0022,0.0001)

Freq = 
c(0,0,197284,497395,613062,366975,181037,87926,43432,26889,29728,14877,8691,6457,6778,1926,4543,123,37,0)
Size = 
c(0.0625,0.1875,0.3125,0.4375,0.5625,0.6875,0.8125,0.937,1.063,1.188,1.375,1.625,1.875,2.125,2.375,2.75,3.25,3.75,4.25,4.75)

x-rep(Size, Freq)

# histogram of probability
hist(x, breaks=Size, freq=TRUE, xlab=Drop Size, ylab=No. of Drops)

dev.new()
# Find the parameters of the gamma curve from the PDF
library(MASS)
fitdistr(PDF,gamma)

# scale=0.4495207, shape=7.1923309

#plot the gamma curve with the found parameters
curve(dgamma(x, scale=.4495207, shape=7.1923309),from=0, to=16, main=Gamma
distribution, ylab=Probability)

# add the points of the PDF from the data
points(PDF)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 'cem' for r 2.14.2

2013-05-20 Thread Kimberley Armstrong
Hello,
I am trying to use R for propensity score matching in SPSS.  I have version 21 
of SPSS and I downloaded R 2.14.2 as directed as well as the R Essentials 
plug-in.  I have run a test for R and it appears to be running correctly.  I 
then downloaded psmatching3 and have tried to use the PS matching dialog in 
SPSS.  However, I continue to run into problems as SPSS reports that there is 
no 'cem' file.  I have tried to download cem separately from your website (both 
the new and the older version) and to install it either in R or as an extension 
in SPSS but I receive the following errors:

IN R:
utils:::menuInstallLocal()
Warning in install.packages(choose.files(, filters = Filters[c(zip,  :
  'lib = C:/Program Files/R/R-2.14.2/library' is not writable
Error in install.packages(choose.files(, filters = Filters[c(zip,  : 
  unable to create '~/R/library'   $HOME/.Renviron'
In addition: Warning message:
In dir.create(userdir, recursive = TRUE) :
  cannot create dir 'C:\Users\Kimberley\Documents\R\library'   $HOME', reason 
'Invalid argument'

In SPSS:

GET
  FILE='C:\Users\Kimberley\Documents\WB Somalia\R Testing\Bor Ber Sheik Ainabo 
merged -and hacked - Copy.sav'.
DATASET NAME DataSet1 WINDOW=FRONT.
SET SEED = 1234.
SET PRINTBACK=NONE.
Loading required package: MASS
##
##  MatchIt (Version 2.4-20, built: 2011-10-24)
##  Please refer to http://gking.harvard.edu/matchit for full documentation
##  or help.matchit() for help with commands supported by MatchIt.
##
Package SparseM (0.97) loaded.
   To cite, see citation(SparseM)

Warning message:
In library(cem, logical.return = TRUE) : there is no package called 'cem'
Installing package(s) into 'C:/Program Files/IBM/SPSS/Statistics/21/extensions'
(as 'lib' is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
  package 'cem' is not available (for R version 2.14.2)
Error in library(cem) : there is no package called 'cem'
Warning message:
In OK() : No warnings in estimation or matching procedure
Error: could not find function imbalance

I would definitely appreciate any suggestions or feedback! 

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.


[R] R for windows GUI front-end has stopped working

2013-05-20 Thread Naser Jamil
Dear R-users,
May I seek your attention please! I have a long R code, which runs most of
the time quite nicely and provides necessary results. However, often it
provides a message like  R for windows GUI front-end has stopped working
and just stops working. I'm running the program in Windows 2007. Is there
any way out? Any suggestion in this regard will be more than great!!

Many thanks for your time.


Regards,
Jamil.

[[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] Generate positive definite matrix with constraints

2013-05-20 Thread Gabor Grothendieck
On Mon, May 20, 2013 at 10:01 AM, mary mary.d...@libero.it wrote:

 Thank you but I want to create a matrix (4,4) or (8,8) not just only a (2,2)
 matrix...


provide an m0 matrix of the appropriate dimensions and change 2 to the
new dimension in the relevant lines.


--
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] help with 'cem' for r 2.14.2

2013-05-20 Thread Duncan Murdoch

On 13-05-20 2:18 PM, Kimberley Armstrong wrote:

Hello,
I am trying to use R for propensity score matching in SPSS.  I have version 21 
of SPSS and I downloaded R 2.14.2 as directed as well as the R Essentials 
plug-in.


I think you need to talk to SPSS support for this.  We have no 
connection with SPSS here.


As well, the current release of R is 3.0.1.  R 2.14.2 is about 15 months 
old; that's ancient history as far as we're concerned (though it may be 
cutting edge for SPSS).


Duncan Murdoch


I have run a test for R and it appears to be running correctly.  I then 
downloaded psmatching3 and have tried to use the PS matching dialog in 
SPSS.  However, I continue to run into problems as SPSS reports that 
there is no 'cem' file.  I have tried to download cem separately from 
your website (both the new and the older version) and to install it 
either in R or as an extension in SPSS but I receive the following errors:


IN R:
utils:::menuInstallLocal()
Warning in install.packages(choose.files(, filters = Filters[c(zip,  :
   'lib = C:/Program Files/R/R-2.14.2/library' is not writable
Error in install.packages(choose.files(, filters = Filters[c(zip,  :
   unable to create '~/R/library'   $HOME/.Renviron'
In addition: Warning message:
In dir.create(userdir, recursive = TRUE) :
   cannot create dir 'C:\Users\Kimberley\Documents\R\library'   $HOME', 
reason 'Invalid argument'

In SPSS:

GET
   FILE='C:\Users\Kimberley\Documents\WB Somalia\R Testing\Bor Ber Sheik Ainabo 
merged -and hacked - Copy.sav'.
DATASET NAME DataSet1 WINDOW=FRONT.
SET SEED = 1234.
SET PRINTBACK=NONE.
Loading required package: MASS
##
##  MatchIt (Version 2.4-20, built: 2011-10-24)
##  Please refer to http://gking.harvard.edu/matchit for full documentation
##  or help.matchit() for help with commands supported by MatchIt.
##
Package SparseM (0.97) loaded.
To cite, see citation(SparseM)

Warning message:
In library(cem, logical.return = TRUE) : there is no package called 'cem'
Installing package(s) into 'C:/Program Files/IBM/SPSS/Statistics/21/extensions'
(as 'lib' is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
   package 'cem' is not available (for R version 2.14.2)
Error in library(cem) : there is no package called 'cem'
Warning message:
In OK() : No warnings in estimation or matching procedure
Error: could not find function imbalance

I would definitely appreciate any suggestions or feedback!

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.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] as.vector with mode=list and POSIXct

2013-05-20 Thread Alexandre Sieira
I was trying to convert a vector of POSIXct into a list of POSIXct, However, I 
had a problem that I wanted to share with you.

Works fine with, say, numeric:


 v = c(1, 2, 3)
 v
[1] 1 2 3
 str(v)
 num [1:3] 1 2 3
 l = as.vector(v, mode=list)
 l
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

 str(l)
List of 3
 $ : num 1
 $ : num 2
 $ : num 3

If you try it with POSIXct, on the other hand…


 v = c(Sys.time(), Sys.time())
 v
[1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT
 str(v)
 POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07
 l = as.vector(v, mode=list)
 l
[[1]]
[1] 1369083728

[[2]]
[1] 1369083728

 str(l)
List of 2
 $ : num 1.37e+09
 $ : num 1.37e+09

The POSIXct values are coerced to numeric, which is unexpected.

The documentation for as.vector says: The default method handles 24 input 
types and 12 values of type: the details of most coercions are undocumented and 
subject to change. It would appear that treatment for POSIXct is either 
missing or needs adjustment.

Unlist (for the reverse) is documented to converting to base types, so I can't 
complain. Just wanted to share that I ended up giving up on vectorization and 
writing the two following functions:


unlistPOSIXct - function(x) {
  retval = rep(Sys.time(), length(x))
  for (i in 1:length(x)) retval[i] = x[[i]]
  return(retval)
}

listPOSIXct - function(x) {
  retval = list()
  for (i in 1:length(x)) retval[[i]] = x[i]
  return(retval)
}

Is there a better way to do this (other than using *apply instead of for above) 
that better leverages vectorization? Am I missing something here?

Thanks!




-- 
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor

The truth is rarely pure and never simple.
Oscar Wilde, The Importance of Being Earnest, 1895, Act I__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] as.vector with mode=list and POSIXct

2013-05-20 Thread William Dunlap
Try using as.list(x) instead of as.vector(x, mode=list).
The former has a method for POSIXct; the latter does not.

   x - as.POSIXct(c(2013-05-20 14:28, 2013-11-30 22:10), tz=US/Pacific) 
   x
  [1] 2013-05-20 14:28:00 PDT 2013-11-30 22:10:00 PST
   as.list(x)
  [[1]]
  [1] 2013-05-20 14:28:00 PDT
  
  [[2]]
  [1] 2013-11-30 22:10:00 PST

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 Alexandre Sieira
 Sent: Monday, May 20, 2013 2:10 PM
 To: r-help@r-project.org
 Subject: [R] as.vector with mode=list and POSIXct
 
 I was trying to convert a vector of POSIXct into a list of POSIXct, However, 
 I had a
 problem that I wanted to share with you.
 
 Works fine with, say, numeric:
 
 
  v = c(1, 2, 3)
  v
 [1] 1 2 3
  str(v)
  num [1:3] 1 2 3
  l = as.vector(v, mode=list)
  l
 [[1]]
 [1] 1
 
 [[2]]
 [1] 2
 
 [[3]]
 [1] 3
 
  str(l)
 List of 3
  $ : num 1
  $ : num 2
  $ : num 3
 
 If you try it with POSIXct, on the other hand…
 
 
  v = c(Sys.time(), Sys.time())
  v
 [1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT
  str(v)
  POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07
  l = as.vector(v, mode=list)
  l
 [[1]]
 [1] 1369083728
 
 [[2]]
 [1] 1369083728
 
  str(l)
 List of 2
  $ : num 1.37e+09
  $ : num 1.37e+09
 
 The POSIXct values are coerced to numeric, which is unexpected.
 
 The documentation for as.vector says: The default method handles 24 input 
 types and
 12 values of type: the details of most coercions are undocumented and subject 
 to
 change. It would appear that treatment for POSIXct is either missing or needs
 adjustment.
 
 Unlist (for the reverse) is documented to converting to base types, so I 
 can't complain.
 Just wanted to share that I ended up giving up on vectorization and writing 
 the two
 following functions:
 
 
 unlistPOSIXct - function(x) {
   retval = rep(Sys.time(), length(x))
   for (i in 1:length(x)) retval[i] = x[[i]]
   return(retval)
 }
 
 listPOSIXct - function(x) {
   retval = list()
   for (i in 1:length(x)) retval[[i]] = x[i]
   return(retval)
 }
 
 Is there a better way to do this (other than using *apply instead of for 
 above) that better
 leverages vectorization? Am I missing something here?
 
 Thanks!
 
 
 
 
 --
 Alexandre Sieira
 CISA, CISSP, ISO 27001 Lead Auditor
 
 The truth is rarely pure and never simple.
 Oscar Wilde, The Importance of Being Earnest, 1895, Act I
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] as.vector with mode=list and POSIXct

2013-05-20 Thread Alexandre Sieira
So it does. I had tried list() but not as.list(). Silly me. :)

Thank you very much, William.

-- 
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor

The truth is rarely pure and never simple.
Oscar Wilde, The Importance of Being Earnest, 1895, Act I
On 20 de maio de 2013 at 18:32:35, William Dunlap (wdun...@tibco.com) wrote:
Try using as.list(x) instead of as.vector(x, mode=list).  
The former has a method for POSIXct; the latter does not.  

 x - as.POSIXct(c(2013-05-20 14:28, 2013-11-30 22:10), tz=US/Pacific)  
 x  
[1] 2013-05-20 14:28:00 PDT 2013-11-30 22:10:00 PST  
 as.list(x)  
[[1]]  
[1] 2013-05-20 14:28:00 PDT  

[[2]]  
[1] 2013-11-30 22:10:00 PST  

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 Alexandre Sieira  
 Sent: Monday, May 20, 2013 2:10 PM  
 To: r-help@r-project.org  
 Subject: [R] as.vector with mode=list and POSIXct  
  
 I was trying to convert a vector of POSIXct into a list of POSIXct, However, 
 I had a  
 problem that I wanted to share with you.  
  
 Works fine with, say, numeric:  
  
  
  v = c(1, 2, 3)  
  v  
 [1] 1 2 3  
  str(v)  
  num [1:3] 1 2 3  
  l = as.vector(v, mode=list)  
  l  
 [[1]]  
 [1] 1  
  
 [[2]]  
 [1] 2  
  
 [[3]]  
 [1] 3  
  
  str(l)  
 List of 3  
  $ : num 1  
  $ : num 2  
  $ : num 3  
  
 If you try it with POSIXct, on the other hand…  
  
  
  v = c(Sys.time(), Sys.time())  
  v  
 [1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT  
  str(v)  
  POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07  
  l = as.vector(v, mode=list)  
  l  
 [[1]]  
 [1] 1369083728  
  
 [[2]]  
 [1] 1369083728  
  
  str(l)  
 List of 2  
  $ : num 1.37e+09  
  $ : num 1.37e+09  
  
 The POSIXct values are coerced to numeric, which is unexpected.  
  
 The documentation for as.vector says: The default method handles 24 input 
 types and  
 12 values of type: the details of most coercions are undocumented and subject 
 to  
 change. It would appear that treatment for POSIXct is either missing or 
 needs  
 adjustment.  
  
 Unlist (for the reverse) is documented to converting to base types, so I 
 can't complain.  
 Just wanted to share that I ended up giving up on vectorization and writing 
 the two  
 following functions:  
  
  
 unlistPOSIXct - function(x) {  
   retval = rep(Sys.time(), length(x))  
   for (i in 1:length(x)) retval[i] = x[[i]]  
   return(retval)  
 }  
  
 listPOSIXct - function(x) {  
   retval = list()  
   for (i in 1:length(x)) retval[[i]] = x[i]  
   return(retval)  
 }  
  
 Is there a better way to do this (other than using *apply instead of for 
 above) that better  
 leverages vectorization? Am I missing something here?  
  
 Thanks!  
  
  
  
  
 --  
 Alexandre Sieira  
 CISA, CISSP, ISO 27001 Lead Auditor  
  
 The truth is rarely pure and never simple.  
 Oscar Wilde, The Importance of Being Earnest, 1895, Act I__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] old Windows binary for GBM package

2013-05-20 Thread Andrew Z
Is there a place to an old version (GBM 1.6 or 2.0) of the Windows
64-bit binary for the GBM package?

In GBM 2.1, CV does not work on any of my data sets, so I reported it
to https://code.google.com/p/gradientboostedmodels/ . However, I would
like to soon continue to use GBM for a project, and I prefer not to
set up a build environment on Windows to build from source.


Andrew

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] old Windows binary for GBM package

2013-05-20 Thread David Winsemius

On May 20, 2013, at 2:24 PM, Andrew Z wrote:

 Is there a place to an old version (GBM 1.6 or 2.0) of the Windows
 64-bit binary for the GBM package?
 
 In GBM 2.1, CV does not work on any of my data sets, so I reported it
 to https://code.google.com/p/gradientboostedmodels/ . However, I would
 like to soon continue to use GBM for a project, and I prefer not to
 set up a build environment on Windows to build from source.
 

Several mirrors have old binaries. This happens to be the one closest to me:

http://cran.cnr.berkeley.edu/web/packages/

http://cran.cnr.berkeley.edu/bin/windows/contrib

http://cran.cnr.berkeley.edu/bin/windows/contrib/2.14/gbm_2.0-8.zip

Go Bears!
-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] R for windows GUI front-end has stopped working

2013-05-20 Thread Uwe Ligges



On 20.05.2013 18:10, Naser Jamil wrote:

Dear R-users,
May I seek your attention please! I have a long R code, which runs most of
the time quite nicely and provides necessary results. However, often it
provides a message like  R for windows GUI front-end has stopped working
and just stops working. I'm running the program in Windows 2007. Is there
any way out? Any suggestion in this regard will be more than great!!


A crash is always a bug, but now the question is where:

What is Windows 2007?

Which R version are we talking about? R-3.0.1 or R-devel?

Where is reproducible code?

Is there any package or self written external code involved in which 
case it may be not base R that causes the error.


Please re-read the posting guide that suggests how to ask questions so 
that we are able to help.


Best,
Uwe Ligges



Many thanks for your time.


Regards,
Jamil.

[[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] old Windows binary for GBM package

2013-05-20 Thread Uwe Ligges



On 20.05.2013 23:24, Andrew Z wrote:

Is there a place to an old version (GBM 1.6 or 2.0) of the Windows
64-bit binary for the GBM package?

In GBM 2.1, CV does not work on any of my data sets, so I reported it
to https://code.google.com/p/gradientboostedmodels/ . However, I would
like to soon continue to use GBM for a project, and I prefer not to
set up a build environment on Windows to build from source.


At least CRAN does not keep copies of old binaries, there is a version 
2.0-8 for R-2.14.x, and version 1.6-3.1 for R-2.13.x, but hese R 
versions are rather ancient, hence I'd suggest to try to learn how to 
install from sources, in most cases it is not too hard.


Or ask the maintainer for a fix again so that we see a proper update on 
CRAN soon.


Best,
Uwe Ligges






Andrew

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] stack object layer names not visible

2013-05-20 Thread Uwe Ligges



On 15.05.2013 17:42, Fabio Berzaghi wrote:

I use to be able to see the layer names of a RasterStack by just typing
its name but now I only get this

class   : RasterStack
dimensions  : 70, 180, 12600  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent  : -80, 10, 50, 85  (xmin, xmax, ymin, ymax)
coord. ref. : NA

If I do plot(s) then I can see all the layers and their names.

Why is this happening?



Perhaps the package got updated?

Best,
Uwe Ligges





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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] as.vector with mode=list and POSIXct

2013-05-20 Thread Jeff Newmiller
I don't know what you plan to do with this list, but lists are quite a bit less 
efficient than fixed-mode vectors, so you are likely losing a lot of 
computational speed by using this list. I don't hesitate to use simple data 
frames (lists of vectors), but processing lists is on par with for loops, not 
vectorized computation. It may still support a simpler model of computation, 
but that is an analyst comprehension benefit rather than a computational 
efficiency benefit.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Alexandre Sieira alexandre.sie...@gmail.com wrote:

I was trying to convert a vector of POSIXct into a list of POSIXct,
However, I had a problem that I wanted to share with you.

Works fine with, say, numeric:


 v = c(1, 2, 3)
 v
[1] 1 2 3
 str(v)
 num [1:3] 1 2 3
 l = as.vector(v, mode=list)
 l
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

 str(l)
List of 3
 $ : num 1
 $ : num 2
 $ : num 3

If you try it with POSIXct, on the other hand…


 v = c(Sys.time(), Sys.time())
 v
[1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT
 str(v)
 POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07
 l = as.vector(v, mode=list)
 l
[[1]]
[1] 1369083728

[[2]]
[1] 1369083728

 str(l)
List of 2
 $ : num 1.37e+09
 $ : num 1.37e+09

The POSIXct values are coerced to numeric, which is unexpected.

The documentation for as.vector says: The default method handles 24
input types and 12 values of type: the details of most coercions are
undocumented and subject to change. It would appear that treatment for
POSIXct is either missing or needs adjustment.

Unlist (for the reverse) is documented to converting to base types, so
I can't complain. Just wanted to share that I ended up giving up on
vectorization and writing the two following functions:


unlistPOSIXct - function(x) {
  retval = rep(Sys.time(), length(x))
  for (i in 1:length(x)) retval[i] = x[[i]]
  return(retval)
}

listPOSIXct - function(x) {
  retval = list()
  for (i in 1:length(x)) retval[[i]] = x[i]
  return(retval)
}

Is there a better way to do this (other than using *apply instead of
for above) that better leverages vectorization? Am I missing something
here?

Thanks!




-- 
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor

The truth is rarely pure and never simple.
Oscar Wilde, The Importance of Being Earnest, 1895, Act I



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] bar plot with non-zero starting level

2013-05-20 Thread Jim Lemon

On 05/21/2013 12:54 AM, Xianwen Chen wrote:

Hi Jim,

Thank you for the suggestion. I think overlapped rectangles will well
present the message. I'm now trying ggplot2.

Here is the code:

require(ggplot2)
rect_MNL_Delta - data.frame(
xmin - c(1, 3, 5, 7, 9, 11, 13),
xmax - xmin + 1,
ymin - c(16.7026, 14.9968, 16.0630, 17.7510, -5.01694, -.44146, 1.45884),
ymax - c(21.1602, 18.7613, 19.1367, 23.6730, 2.26564, 3.08630, 3.39865)
)
rect_GMNL - data - data.frame(
xmin - c(1, 3, 5, 7, 9, 11, 13),
xmax - xmin + 1,
ymin - c(17.20, 16.32, 15.86, 18.12, -8.86, -0.03, 0.95),
ymax - c(20.12, 18.60, 18.14, 22.29, 3.03, 3.57, 2.81)
)

ggplot() +
geom_rect(data = rect_MNL_Delta, aes(xmin = xmin, xmax = xmax, ymin =
ymin, ymax = ymax), fill = blue, alpha = 0.1) +
geom_rect(data = rect_GMNL, aes(xmin = xmin, xmax = xmax, ymin = ymin,
ymax = ymax), fill = green, alpha = 0.1)

The problem is that the second geom_rect() fully covered the first
geom_rect(), instead of overlapping. Another issue is that I don't know
how to set labels on x-axis, instead of the current ticks. I would like
to have for instance 'Farmed cod' under the first rectangle.


Hi Xianwen,
The problem with the overlapping is in the last two lines. These should 
read:


geom_rect(data = rect_MNL_Delta, aes(xmin = 
rect_MNL_Delta$xmin, xmax = rect_MNL_Delta$xmax, ymin = 
rect_MNL_Delta$ymin, ymax = rect_MNL_Delta$ymax), fill = blue, alpha = 
0.1) +
geom_rect(data = rect_GMNL, aes(xmin = rect_GMNL$xmin, xmax = 
rect_GMNL$xmax, ymin = rect_GMNL$ymin, ymax = rect_GMNL$ymax), fill = 
green, alpha = 0.1)


I am not terribly familiar with ggplot, but you should be able to get 
custom tick labels on your horizontal axis. I have to go out now, but 
when I return I'll have a look at the scale functions, as I think this 
is hiding in there.


Jim

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


Re: [R] Gamma curve fit to data with specific bins

2013-05-20 Thread Rui Barradas

Hello,

You are fitting a vector other than the vector 'x'.
And you are mistaking the parameter scale for rate.

est - fitdistr(x,gamma)$estimate


#plot the gamma curve with the found parameters
hist(x, breaks=Size, freq=FALSE, xlab=Drop Size, ylab=No. of Drops)
curve(dgamma(x, rate=est[rate], shape=est[shape]),from=0, to=16, 
main=Gamma

distribution, ylab=Probability, add = TRUE, col = red)


Hope this helps,

Rui Barradas

Em 20-05-2013 16:44, Lorentz, Andrew escreveu:

Good afternoon,

I have some rainfall drop size data (frequency count within drop size) that is 
already arranged into specific bins (Size). I am looking to fit a gamma curve 
onto a histogram of the data.

At the moment I have been able to create estimate the gamma parameters from the 
PDF of the frequencies. And plot the points on the gamma curve.  However, the 
x-axis is only a count and not the specific drop size values.  Nor have I been 
able to plot the histogram and the curve together.

Could you advise? Many thanks.

Code:
# Load the probability data from the Drop Size Distribution
PDF=c(0.0941,0.2372,0.2923,0.1750,0.0863,0.0419,0.0207,0.0128,0.0142,0.0071,0.0041,0.0031,0.0032,0.0057,0.0022,0.0001)

Freq = 
c(0,0,197284,497395,613062,366975,181037,87926,43432,26889,29728,14877,8691,6457,6778,1926,4543,123,37,0)
Size = 
c(0.0625,0.1875,0.3125,0.4375,0.5625,0.6875,0.8125,0.937,1.063,1.188,1.375,1.625,1.875,2.125,2.375,2.75,3.25,3.75,4.25,4.75)

x-rep(Size, Freq)

# histogram of probability
hist(x, breaks=Size, freq=TRUE, xlab=Drop Size, ylab=No. of Drops)

dev.new()
# Find the parameters of the gamma curve from the PDF
library(MASS)
fitdistr(PDF,gamma)

# scale=0.4495207, shape=7.1923309

#plot the gamma curve with the found parameters
curve(dgamma(x, scale=.4495207, shape=7.1923309),from=0, to=16, main=Gamma
distribution, ylab=Probability)

# add the points of the PDF from the data
points(PDF)

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



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


[R] how to GREP out a string like this......THANKS.

2013-05-20 Thread Hon Kit (Stephen) Wong
Dear ALl,

I hope you could help me out on this simple problem. I have many thousand lines 
like this:
NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54156

I want to extract the string inside the first // //, in this case is Egf16. 


How do I apply grep function?

Thanks.

Stephen HK Wong

Stephen HK Wong
Research Associate,Cleary Lab
Lab Phone: 650-723-5340
MC 5457 
Lokey Stem Cell Research Building 
265 Campus Drive, Rm. G2035 
Stanford, California 94305-5324

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 GREP out a string like this......THANKS.

2013-05-20 Thread David Winsemius

On May 20, 2013, at 4:45 PM, Hon Kit (Stephen) Wong wrote:

 Dear ALl,
 
 I hope you could help me out on this simple problem. I have many thousand 
 lines like this:
 NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54156
 
 I want to extract the string inside the first // //, in this case is Egf16. 

 strsplit(NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM 
 // 54156, split= // )[[1]][2]
[1] Egfl6

You can use;

lapply( lines, function(l) strsplit(l,  // )[[1]][2] )


 
 
 How do I apply grep function?

Well, grep is only going to give you a test and you want a replacement or 
extraction function. sub or gsub would be possibilities but they are greedy so 
its a bit more difficult to constrain their targeting to only the first  and 
second //.

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] how to GREP out a string like this......THANKS.

2013-05-20 Thread William Dunlap
You suggested
   lapply( lines, function(l) strsplit(l,  // )[[1]][2] )

strsplit is vectorized so the following is equivalent but simpler and quicker:
   lapply(strsplit(lines,  // ), function(x)x[2])

The OP probably wants a character vector, not a list so use sapply or vapply 
(safer
than sapply and a bit quicker).  Any of the following would do:
  vapply(strsplit(lines,  // ), `[`, 2, FUN.VALUE=)
  vapply(strsplit(lines,  // ), function(x)x[2], FUN.VALUE=)
  sapply(strsplit(lines,  // ), `[`, 2) # wrong answer if length(lines)==0


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 David Winsemius
 Sent: Monday, May 20, 2013 5:17 PM
 To: Hon Kit (Stephen) Wong
 Cc: r-help@r-project.org
 Subject: Re: [R] how to GREP out a string like this..THANKS.
 
 
 On May 20, 2013, at 4:45 PM, Hon Kit (Stephen) Wong wrote:
 
  Dear ALl,
 
  I hope you could help me out on this simple problem. I have many thousand 
  lines like
 this:
  NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54156
 
  I want to extract the string inside the first // //, in this case is Egf16.
 
  strsplit(NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 
  cM //
 54156, split= // )[[1]][2]
 [1] Egfl6
 
 You can use;
 
 lapply( lines, function(l) strsplit(l,  // )[[1]][2] )
 
 
 
 
  How do I apply grep function?
 
 Well, grep is only going to give you a test and you want a replacement or 
 extraction
 function. sub or gsub would be possibilities but they are greedy so its a bit 
 more difficult
 to constrain their targeting to only the first  and second //.
 
 --
 
 David Winsemius
 Alameda, CA, USA
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] how to GREP out a string like this......THANKS.

2013-05-20 Thread arun
Hi,
May be this helps.

lines- readLines(textConnection(NM_019397 // Egfl6 // EGF-like-domain, 
multiple 6 // X F5|X 71.5 cM // 54156
NM_019397 // Egfl7 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54158))
library(stringr)
word(lines,2,sep= // )
#[1] Egfl6 Egfl7

lines1- readLines(textConnection(NM_019397 // Egfl6 // EGF-like-domain, 
multiple 6 // X F5|X 71.5 cM // 54156
NM_019397 // Egfl7 domain // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 
54158))
 word(lines1,2,sep= // )
#[1] Egfl6    Egfl7 domain
A.K.



- Original Message -
From: Hon Kit (Stephen) Wong hon...@stanford.edu
To: r-help@r-project.org
Cc: 
Sent: Monday, May 20, 2013 7:45 PM
Subject: [R] how to GREP out a string like this..THANKS.

Dear ALl,

I hope you could help me out on this simple problem. I have many thousand lines 
like this:
NM_019397 // Egfl6 // EGF-like-domain, multiple 6 // X F5|X 71.5 cM // 54156

I want to extract the string inside the first // //, in this case is Egf16. 


How do I apply grep function?

Thanks.

Stephen HK Wong

Stephen HK Wong
Research Associate,Cleary Lab
Lab Phone: 650-723-5340
MC 5457 
Lokey Stem Cell Research Building 
265 Campus Drive, Rm. G2035 
Stanford, California 94305-5324

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


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


[R] How many decimal places of information does R actually use in computation?

2013-05-20 Thread Xiao He
Dear R-users:

Hi, I read here (
http://stackoverflow.com/questions/2287616/controlling-digits-in-r) that R
is only accurate up to the 15th decimal place, despite the fact that if you
choose to display more decimal places, it will. I wonder if R uses the
information beyond the 15th decimal place in actual computation. Thanks!


Best,
Xiao

[[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 many decimal places of information does R actually use in computation?

2013-05-20 Thread Bert Gunter
See, e.g.

http://en.wikipedia.org/wiki/Double-precision_floating-point_format

Also in ?print.default  please note:

Large number of digits

Note that for large values of digits, currently for digits = 16, the
calculation of the number of significant digits will depend on the
platform's internal (C library) implementation of sprintf()
functionality.

-- Bert

On Mon, May 20, 2013 at 6:06 PM, Xiao He praguewaterme...@gmail.com wrote:
 Dear R-users:

 Hi, I read here (
 http://stackoverflow.com/questions/2287616/controlling-digits-in-r) that R
 is only accurate up to the 15th decimal place, despite the fact that if you
 choose to display more decimal places, it will. I wonder if R uses the
 information beyond the 15th decimal place in actual computation. Thanks!


 Best,
 Xiao

 [[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] ordered and unordered variables

2013-05-20 Thread meng
Hi all:
If the explainary variables are ordinal,the result of regression is different 
from
unordered variables.But I can't understand the result of regression from 
ordered
variable.
 
The data is warpbreaks,which belongs to R.
 
If I use the unordered variable(tension):Levels: L M H
The result is easy to understand:
Estimate Std. Error t value Pr(|t|)   
(Intercept)36.39   2.80  12.995   2e-16 ***
tensionM  -10.00   3.96  -2.525 0.014717 * 
tensionH  -14.72   3.96  -3.718 0.000501 ***

If I use the ordered variable(tension):Levels: L  M  H
I don't know how to explain the result:
   Estimate Std. Error t value Pr(|t|)   
(Intercept)   28.148  1.617  17.410   2e-16 ***
tension.L-10.410  2.800  -3.718 0.000501 ***
tension.Q  2.155  2.800   0.769 0.445182   
 
What's tension.L and tension.Q stands for?And how to explain the result 
then?
 
Many 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.