[R] how to improve summary.lm

2011-08-21 Thread Oliver Kullmann
Hello,

I need a shorter summary.lm, instead of

Call:
lm(formula = E$t ~ E$cfs)

Residuals:
   Min1QMedian3Q   Max 
-0.239674 -0.007694  0.006430  0.014330  2.496551 

Coefficients:
  Estimate Std. Error t value Pr(|t|)
(Intercept) -1.994e-02  1.419e-04  -140.5   2e-16 ***
E$cfs1.675e-05  4.714e-09  3552.7   2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.03238 on 65268 degrees of freedom
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949 
F-statistic: 1.262e+07 on 1 and 65268 DF,  p-value:  2.2e-16 


I need


lm(formula = E$t ~ E$cfs)
  Estimate Std. Error t value Pr(|t|)  
(Intercept) -1.994e-02  1.419e-04  -140.5   2e-16 ***
E$cfs1.675e-05  4.714e-09  3552.7   2e-16 ***
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949  


I looked at the code of summary.lm, with the intention
to copy parts of it into a new function short_sum_lm,
but couldn't find the parts I'm interested in.

I hope it's not too complicated to achieve that.
(In general it would be great to have more influence
on the summary-function -- typically it's too spacious.)

Thanks for your attention

Oliver

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] AFT model time-dependent with weibull distribution

2011-08-21 Thread Göran Broström
On Sat, Aug 20, 2011 at 7:33 PM, JPF xpfen...@gmail.com wrote:

 Göran Broström wrote:


 Good. Do you still need answers to your other questions?



 Yes. Could answer the following two questions:

 1- Can I use phreg function to estimate  a model with time-dependent
 covariates? In case of a positive answer, how?

Yes. You do it in the way you did it with your first example. No 'id'
argument is needed (or allowed) in the call to phreg. The reason is
that in PH regression, the hazard function at any time depends only on
the covariate value at that time point. In the AFT model, on the other
hand, the hazard function at time  t  depends on all covariate values
in the interval (0, t). Therefore aftreg needs the 'id' argument, but
phreg does not.


 2- I could not find any example that clearly explains how to interpret
 aftreg output. Specially, refering to the diference between survreg and
 aftreg output (intercept and sign of the estimates).

I think you already answered that question. You can read more about it
in the vignette about parametric models in eha.

G.

 I include below an example of output of a regression with coxph, survreg,
 phreg and aftreg and a time-independent variable. I would appreciate if you
 could explain it or provide an external example that explains how it works.

 n=26
 events=25
 time at risk=45

 a/

 coxph(Surv(time,s) ~ Z1,  data=data.frame(data))

     coef     exp(coef)  se(coef)    z     p
 Z1 0.0249      1.03      0.00907 2.75 0.006


 b/

 phreg(Surv(time,s) ~ Z1,  data=data.frame(data), dist=weibull)

 Covariate          W.mean      Coef Exp(Coef)  se(Coef)    Wald p
 Z1                      43.689     0.033     1.033     0.009     0.000

 log(scale)                          0.641     1.899     0.065     0.000
 log(shape)                         1.172     3.230     0.158     0.000

 Max. log. likelihood      -22.135
 LR test statistic         13.1
 Degrees of freedom        1
 Overall p-value           0.000302689


 c/

 aftreg(Surv(time,s) ~ Z1,  data=data.frame(data), dist=weibull)

 Covariate          W.mean      Coef Exp(Coef)  se(Coef)    Wald p
 mas                  43.689       0.010    1.010     0.002     0.000

 log(scale)                          1.147     3.149     0.141     0.000
 log(shape)                         1.172     3.230     0.158     0.000

 Max. log. likelihood      -22.135
 LR test statistic         13.1
 Degrees of freedom        1
 Overall p-value         0.000302692


 d/

 survreg(Surv(time,s) ~ Z1,  data=data.frame(data), dist=weibull)

                      Value     Std. Error     z        p
 (Intercept)      1.1476    0.13498     8.50  1.87e-17
 mas               -0.0101   0.00232    -4.34  1.45e-05
 Log(scale)      -1.1724    0.15787    -7.43 1.11e-13

 Scale= 0.310

 Weibull distribution
 Loglik(model)= -22.1   Loglik(intercept only)= -28.7
        Chisq= 13.05 on 1 degrees of freedom, p= 3e-04
 Number of Newton-Raphson Iterations: 5


 Thank you very much,

 J







 --
 View this message in context: 
 http://r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3757387.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.




-- 
Göran Broström

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

2011-08-21 Thread Jorge I Velez

Hi Oliver,

For the the output you would like to have, you may take a look at

names(summary(yourmodel))
str(summary(yourmodel))

The above will help you to extract the components you need from the lm 
object.


Below is my attempt to do what you want. However, you will need to work 
a little more in order to get the *** besides the p-values ;-)   Also, 
note that it is assumed that the lm function is used to build up the 
linear model.


# function
myout - function(lmfit, k = 22){
 res - summary(fit)
 cat(rep(--, k), \n)
 print(res$call)
 print(res$coef)
 cat('Multiple R-squared:', res$r.squared, '   Adjusted 
R-squared:', res$adj.r.squared, \n)

 cat(rep(--, k), \n)
 }

# some data
set.seed(123)
x1 - rnorm(100)
x2 - rnorm(100)
y - .5 + 1.2*x1 - .2*x2 +  rnorm(100)

# linear model
fit - lm(y ~ x1 + x2)
myout(fit)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
lm(formula = y ~ x1 + x2)
  Estimate Std. Error   t value Pr(|t|)
(Intercept)  0.6350654 0.09614007  6.605627 2.129617e-09
x1   1.0668285 0.10486949 10.172915 5.677194e-17
x2  -0.1761887 0.09899469 -1.779779 7.824368e-02
Multiple R-squared: 0.5284765Adjusted R-squared: 0.5187544
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

HTH,
Jorge


On 8/21/11 3:16 AM, Oliver Kullmann wrote:

Hello,

I need a shorter summary.lm, instead of

Call:
lm(formula = E$t ~ E$cfs)

Residuals:
Min1QMedian3Q   Max
-0.239674 -0.007694  0.006430  0.014330  2.496551

Coefficients:
   Estimate Std. Error t value Pr(|t|)
(Intercept) -1.994e-02  1.419e-04  -140.52e-16 ***
E$cfs1.675e-05  4.714e-09  3552.72e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03238 on 65268 degrees of freedom
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949
F-statistic: 1.262e+07 on 1 and 65268 DF,  p-value:  2.2e-16


I need


lm(formula = E$t ~ E$cfs)
   Estimate Std. Error t value Pr(|t|)
(Intercept) -1.994e-02  1.419e-04  -140.52e-16 ***
E$cfs1.675e-05  4.714e-09  3552.72e-16 ***
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949


I looked at the code of summary.lm, with the intention
to copy parts of it into a new function short_sum_lm,
but couldn't find the parts I'm interested in.

I hope it's not too complicated to achieve that.
(In general it would be great to have more influence
on the summary-function -- typically it's too spacious.)

Thanks for your attention

Oliver

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

2011-08-21 Thread David Winsemius


On Aug 21, 2011, at 3:16 AM, Oliver Kullmann wrote:


Hello,

I need a shorter summary.lm, instead of

Call:
lm(formula = E$t ~ E$cfs)

Residuals:
  Min1QMedian3Q   Max
-0.239674 -0.007694  0.006430  0.014330  2.496551

Coefficients:
 Estimate Std. Error t value Pr(|t|)
(Intercept) -1.994e-02  1.419e-04  -140.5   2e-16 ***
E$cfs1.675e-05  4.714e-09  3552.7   2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03238 on 65268 degrees of freedom
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949
F-statistic: 1.262e+07 on 1 and 65268 DF,  p-value:  2.2e-16


I need


lm(formula = E$t ~ E$cfs)
 Estimate Std. Error t value Pr(|t|)
(Intercept) -1.994e-02  1.419e-04  -140.5   2e-16 ***
E$cfs1.675e-05  4.714e-09  3552.7   2e-16 ***
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9949


I looked at the code of summary.lm, with the intention
to copy parts of it into a new function short_sum_lm,
but couldn't find the parts I'm interested in.

I hope it's not too complicated to achieve that.
(In general it would be great to have more influence
on the summary-function -- typically it's too spacious.)


When you simply type summary.lm there is an implicit call to  
print.summary.lm but its code is not visible unless you use  
getAnywhere(print.summary.lm ). Reading the code you find that the  
coefficient matrix and the significance stars are handled by a  
function , so this should give you what you want:


printCoefmat(summary(model)$coefficients)

--
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] how to improve summary.lm

2011-08-21 Thread Oliver Kullmann
 When you simply type summary.lm there is an implicit call to
 print.summary.lm but its code is not visible unless you use
 getAnywhere(print.summary.lm ).

Aha, that's great -- now I see all the \n (and can get rid off
them ;-)).

 Reading the code you find that the
 coefficient matrix and the significance stars are handled by a
 function , so this should give you what you want:
 
 printCoefmat(summary(model)$coefficients)
 

For the record, now I'm using

short_summary_lm = function(L) {
  S = summary(L)
  printCoefmat(S$coefficients, signif.legend=FALSE)
  digits = max(3,getOption(digits)-3)
  cat(R-squared:, formatC(S$r.squared, digits = digits), \n)
}

Thanks!

Oliver

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Eran Eidinger
Hello all,

I need to zoom in and out and travel(pan) inside a plot, like you can do
on a Matlab plot.

If possible, I would also like the option to use the mouse to set a marker
on the graph and get the (x,y) data for it, again, like in Matlab.

Is this possible in R with the regular packages, or do you maybe know a
different package that will allow this?

Eran.
*


*

[[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] Build a package - check error

2011-08-21 Thread Erich Neuwirth
On 8/20/2011 3:37 PM, Uwe Ligges wrote:
 ?.First.lib has an example:
 
 ## Suppose a package needs to call a DLL named 'fooEXT',
 ## where 'EXT' is the system-specific extension.  Then you should use
 .First.lib - function(lib, pkg)
   library.dynam(foo, pkg, lib)
 

Shouldn't the first line here be

 ## Suppose a package needs to call a DLL named 'foo.EXT',
 ^

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

2011-08-21 Thread Michael Dewey

At 18:21 20/08/2011, Uwe Ligges wrote:



On 20.08.2011 19:04, David Winsemius wrote:


On Aug 20, 2011, at 12:32 PM, Uwe Ligges wrote:


[snip original problem]


David,

I think there are some good examples on the help page. What is 
missing? What is not clearly explained? If a longer tutorial is 
needed, that may be an article for the R Help Desk in The R Journal. 
Anybody volunteering?


Uwe
I think the problem is that those of us who do not understand are in 
such a state of ignorance that we do not know what it is that we do 
not understand. I have resigned myself to the realisation that there 
are a very small number of things about R which I shall never 
understand and always solve by trial and error and the 
parameterisation of reshape is the leading example (closely followed 
by backslashes). I do not think the writers of the documentation are 
at fault here, it is either just inherently difficult to understand 
or my cortex is wired up inappropriately.



Best,
Uwe




So Hadley wrote an alternate facility ... the reshape package that does
not have a reshape function in it but rather two functions 'melt' and
'cast'.


 Your data is all ready molten, i.e. it is in the long format

(in the terminology of the base reshape function) with identifier values
in each row and a single column of values.

  library(reshape)
  cast(dataframe,A~B)
Using C as value column. Use the value argument to cast to override this
choice
A control sample
1 d0 1e+05 1e+05
2 d1 2e+02 3e+02
3 d2 4e+02 5e+02

Basically the cast formula keeps the LHS variables in the rows and hte
RHD variables get arranges in columns. (For reasons that are unclear to
me the dataframe argument was placed first when using positional
argument passing, unlike most other formula methods in R.)





Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html

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

2011-08-21 Thread Salvo Mac
 I've   attached a sample of the data sets, this is my full code.

#R 2.13
#library(survival)
#library(Hmisc)
#library(splines)
library(rms)
train-as.data.frame( train-read.csv(G:\\train.txt, header=T, sep=\t))
test-as.data.frame( test-read.table(G:\\test.txt, header=T, sep=\t))
f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
val.surv(f.1, newdata=test, u=10)


#plot(calibrate(f.1, u=30, B=20))






From: David Winsemius dwinsem...@comcast.net
To: Salvo Mac salvo_...@yahoo.com
Cc: r-help@R-project.org r-help@r-project.org
Sent: Sunday, August 21, 2011 5:29 AM
Subject: Re: [R] val.surv


On Aug 20, 2011, at 10:25 PM, Salvo Mac wrote:

 The test and train are like split data sets, contain similar variables but 
 from different countries so the two sets are somehow  independent. And yes it 
 is a data frame.

What is a data.frame? test and train may be dataframes, but test[, age] is 
not a dataframe.

 So I extracted age, time and event.

Code? The code you offered before would have created a newdata object (yes, a 
data.frame) with a single column bearing the same name as the vector argument 
, test1. Not named age. Try it. do str on such an object:

str(dataframe(test1))


 So test is data frame,(age, time, event). does that suffice?

It certainly does not allow me to reproduce the error you got (which I still 
think is probably related to the structure of your argument to newdata.)

That's all I can say without data and code.

--David.


 
 
 
 
 From: David Winsemius dwinsem...@comcast.net
 
 Cc: r-help@R-project.org r-help@r-project.org
 Sent: Sunday, August 21, 2011 3:19 AM
 Subject: Re: [R] val.surv
 
 
 On Aug 20, 2011, at 8:08 PM, Salvo Mac wrote:
 
 Thanks David
 
 However, I tried your trick on val.surv with newdata=test['age'] but still 
 didn't work.
 Still gives the same error message:
 
 Error in val.surv(f.1, newdata = test1[age], u = 10) :
    dims [product 1797] do not match the length of object [2496]
 In addition: Warning message:
 In est.surv + S[, 1] :
    longer object length is not a multiple of shorter object length
 
 
 As I said (and you did
 not act  upon):
 
 The fundamental thing you are doing wrong for q1  is failing to unambiguously 
 describe the test object.
 
 I said it was a guess. Now stop wasting our time and offer what is needed.
 
 --david.
 
 Salvo
 
 From: David Winsemius dwinsem...@comcast.net
 
 Cc: r-help@R-project.org r-help@r-project.org
 Sent: Sunday, August 21, 2011 12:55 AM
 Subject: Re: [R] val.surv
 
 
 On Aug 20, 2011, at 3:32 PM, Salvo Mac wrote:
 
    Dear R-users,
 
 I  have two questions regarding
 validation and calibration of Survival regression models.
 
 1.  I am trying to calibrate and validate a cox model using val.surv.
 here is my code:
    f.1-cph(Surv(time,event)~age, x=T, y=T, data=train)
    test1-test[,age]
    val.surv(f.1, newdata=data.frame(test1), u=10)
 
    but I get an error message:
 
    Error in val.surv(f.1, newdata = data.frame(testi), u = 10) :
     dims [product 1797] do not match the length of object [2496]
    In addition: Warning message:
 In est.surv + S[, 1] :
     longer object length is not a multiple of shorter object length
 
    I ran the example in the r-documentation but couldn't extract  dxy from 
result.
 
    What am I doing wrong?
 
 The fundamental thing you are doing wrong for q1  is failing to 
 unambiguously describe the test object. I would think that if test were a 
 dataframe then wrapping data.frame around a vector might not get it named 
 correctly as 'age'. You might try newdata= test['age']. Just a guess.
 
 
    2.  In validate and calibrate cph functions. If it is frailty fit, does 
the the bootstrap resample clusters or just individuals
 
 The code above appears to be dependent on the rms package. The frailty 
 function is part of the underlying survival package and I do not see it 
 mentioned in the index for Harrell's RMS text. You will probably need to 
 wait until Frank comes across this. He is generally very good about 
 correction my errors and knowledge gaps.
 
 
 

David Winsemius, MD
West Hartford, CTid  age weight  gender  timeevent
1   32  14  0   183 0
3   56  9   0   12  1
4   42  5   0   183 0
5   79  13  0   4   1
6   30  3   0   183 0
7   19  10  0   183 0
8   18  12  0   3   1
9   26  14  0   183 0
10  24  14  0   1   1
11  35  6   0   183 0
12  78  14  0   2   1
13  22  7   0   183 0
14  48  5   0   183 0
15  49  13  0   183 0
16  61  5   0   183 0
19  82  14  0   6   1
20  22  10  0   183 0
21  32  4   1   

Re: [R] I have a problem with R!!

2011-08-21 Thread Jim Lemon

On 08/21/2011 05:29 AM, nferr...@fceia.unr.edu.ar wrote:

Dear all

i´m working with a program i´ve made in R (using functions that others
created)

to run my program i need a sample. if i generate the sample using  for
example, rnorm(n, mu, sigma) i have no problem

but if i obtain a sample from a column in excel and i copy it, the program
says that there is a mistake: it says Error en `[.data.frame`(data,
indices) : undefined columns selected

my program is:

d- read.delim(clipboard, header = T, dec = ,)
#Para determinar los valores de las componentes del vector de capacidad es
necesario definir primero las especificaciones y el valor objetivo, T, así
como el máximo valor admitido para la proporción de producción no
conforme, a cada lado de los límites de especificaciones#
# Ingrese ahora el valor del límite inferior de especificaciones#
LIE- 13
# Ingrese ahora el valor del límite superior de especificaciones#
LSE- 17
# Ingrese ahora el valor objetivo#
T- 14.5
# Ingrese ahora el máximo valor admitido para la proporción de producción
no conforme a cada lado de los límites de especificaciones#
MA- 0.00135
D- min ((LSE-T), (T-LIE))
compo1- function(data, indices)
{
d- data[indices]
n = length (d)
desvio- sd(d)
y- rep(1:n)
y[x= mean(d)]- 1
y[xmean(d)]- 0
RI1- D/(3*desvio*2*mean(y))
RI2- D/(3*desvio*2*(1-mean(y)))
return (min (RI1, RI2))
}
compo2- function(data, indices)
{
d- data[indices]
c2- (abs(mean(d) - T))/D
return (1-c2)
}
compo3-function(data, indices)
{
d- data[indices]
n- length (d)
y- rep(1:n)
y[d  LIE]- 1
y[d= LIE]- 0
INFE- mean (y);
y- rep(1:n)
y[d  LSE]- 1
y[d= LSE]- 0
SUPE- mean (y);
PPI- (1 - INFE)/(1-MA)
PPS- (1 - SUPE)/(1-MA)
return (min (PPI, PPS))
}
save(file = compo1.RData)
save(file = compo2.RData)
save(file = compo3.RData)
compos- function(data, indices)
{
d- data[indices]
capacidad- c(compo1(d), compo2(d), compo3(d))
return(capacidad)
}
save(file = compos.RData)
require (boot)
vectorcapacidad- boot (d, compos, R = 3000)

ETC. ETC.



WHEN I START MY PROGRAM WRITING:
d- rnorm (n, mu, sigma)

I HAVE NO PROBLEM. BUT WHEN I READ A VECTOR FROM EXCEL, R TELLS ME
Error en `[.data.frame`(data, indices) : undefined columns selected


CAN YOU HELP ME THANK YOU VERY MUCH!

NOEMI FERRERI, ROSARIO, ARGENTINA
SCHOOL OF INDUSTRIAL ENGINEERING


Hi Noemi,
Without some sample data, I can only guess, but I would first try saving 
the Excel spreadsheet in CSV format and then reading the data in with 
read.csv. This might solve your problem.


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] reshape a matrix

2011-08-21 Thread Uwe Ligges



On 21.08.2011 12:54, Michael Dewey wrote:

At 18:21 20/08/2011, Uwe Ligges wrote:



On 20.08.2011 19:04, David Winsemius wrote:


On Aug 20, 2011, at 12:32 PM, Uwe Ligges wrote:


[snip original problem]


David,

I think there are some good examples on the help page. What is
missing? What is not clearly explained? If a longer tutorial is
needed, that may be an article for the R Help Desk in The R Journal.
Anybody volunteering?


Uwe
I think the problem is that those of us who do not understand are in
such a state of ignorance that we do not know what it is that we do not
understand. I have resigned myself to the realisation that there are a
very small number of things about R which I shall never understand and
always solve by trial and error and the parameterisation of reshape is
the leading example (closely followed by backslashes). I do not think
the writers of the documentation are at fault here, it is either just
inherently difficult to understand or my cortex is wired up
inappropriately.


In think tha major problem is that stuff like id and time etc. may 
be misleading, if they do not fit to the context. Don't believe I do 
things correct right away here. Nevertheless, improving the wording of 
the reshape() documentation is not easy at all if we want to be precise. 
Maybe we find another volunteer or I find some time to write a short 
column for the next issue of The R Journal.


Best wishes,
Uwe




Best,
Uwe




So Hadley wrote an alternate facility ... the reshape package that does
not have a reshape function in it but rather two functions 'melt' and
'cast'.


 Your data is all ready molten, i.e. it is in the long format

(in the terminology of the base reshape function) with identifier values
in each row and a single column of values.

 library(reshape)
 cast(dataframe,A~B)
Using C as value column. Use the value argument to cast to override this
choice
A control sample
1 d0 1e+05 1e+05
2 d1 2e+02 3e+02
3 d2 4e+02 5e+02

Basically the cast formula keeps the LHS variables in the rows and hte
RHD variables get arranges in columns. (For reasons that are unclear to
me the dataframe argument was placed first when using positional
argument passing, unlike most other formula methods in R.)





Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] adding text to a plot created with strat.plot() from package rioja

2011-08-21 Thread Uwe Ligges



On 21.08.2011 01:01, Jason Paul Joines wrote:

I completely missed that entering just the function name prints the code
for that function making it even easier to copy and create a custom
version.


Better use the original code as you did before: It preserves the 
comments. Anyway, best way would be to contribute your improvements back 
to the package.


Best,
Uwe Ligges




Jason
===



 Original Message 
Subject: Re: [R] adding text to a plot created with strat.plot() from
package rioja
From: Jason Paul Joines ja...@joines.org
To: r-help@r-project.org
Date: 2011.08.20.Sat.14:48:35

I'm pretty new to R and finding the responsible line would not have
been obvious to me without your help. I downloaded the source for
package Rioja and was surprised to see that each function was supplied
in it's own file. That made it pretty straightforward to copy, modify,
and use my own version of it. Still, it's going to take quite a while
to get familiar with all of the graphical capabilities of R.


Thanks,

Jason
===



 Original Message 
Subject: Re: [R] adding text to a plot created with strat.plot() from
package rioja
From: Uwe Ligges lig...@statistik.tu-dortmund.de
To: Jason Paul Joines ja...@joines.org
Date: 2011.08.20.Sat.8:43:30



On 19.08.2011 18:40, Jason Paul Joines wrote:

I have a plot created with strat.plot() from package rioja. When the
plot is created with scale.percent=FALSE, each x axes is labeled at 0
and its maximum. However, when scale.percent=TRUE, the x axes are not
labeled. I need to use scale.percent=TRUE and I need labels for the
x axes.

I have been able to add labels to the x axes with mtext but it is very
tedious to find the correct position. Is there a better way to do this
or a better way to find the desired coordinates than trial and error?


Yes: You can change the code and suggest your improvements to the
package maintainer, for example. The relevant line in that function
obviously is:

axis(side = 1, at = seq(0, colM[i], by = 10), labels = FALSE)

Uwe Ligges





Jason
===

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Uwe Ligges



On 21.08.2011 10:17, Eran Eidinger wrote:

Hello all,

I need to zoom in and out and travel(pan) inside a plot, like you can do
on a Matlab plot.

If possible, I would also like the option to use the mouse to set a marker
on the graph and get the (x,y) data for it, again, like in Matlab.



Don't know about that feature in Matlab, but see ?locator and ?identify 
for regular R graphics.


Uwe Ligges



Is this possible in R with the regular packages, or do you maybe know a
different package that will allow this?

Eran.
*


*

[[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] Best way to setClass and setMethod for an R package?

2011-08-21 Thread Uwe Ligges



On 21.08.2011 00:48, Jonathan Greenberg wrote:

Folks:

I'm putting together an R package, and I was wondering where,
specifically, I put both class definitions (via setClass) as well as
setMethod calls?  Is there a particular file name I need to use?


No, any file name, e.g.
.../name_of_your_package/R/Name_of_your_class.R


Uwe Ligges




Thanks!

--j



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Build a package - check error

2011-08-21 Thread Uwe Ligges



On 21.08.2011 11:29, Erich Neuwirth wrote:

On 8/20/2011 3:37 PM, Uwe Ligges wrote:

?.First.lib has an example:

## Suppose a package needs to call a DLL named 'fooEXT',
## where 'EXT' is the system-specific extension.  Then you should use
.First.lib- function(lib, pkg)
   library.dynam(foo, pkg, lib)



Shouldn't the first line here be


## Suppose a package needs to call a DLL named 'foo.EXT',

  ^



No, since .dll is the extension in this case:
See ?.Platform which has an element dynlib.ext containing the 
current's platform specific extension.

That one contains the extension such as .dll, .so and so on.

Therefore fooEXT evaluates to foo.so under Linux, for example.

Best,
Uwe











__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Uwe Ligges



On 21.08.2011 15:04, Eran Eidinger wrote:

Thank you Uwe,

That solves the second question.
Still looking for some solution to zooming in and out dynamically.


That is not implemented in standard R graphics. Packages rgl and iplots 
may be able to do that.


Best,
Uwe


Eran.
2011/8/21 Uwe Ligges lig...@statistik.tu-dortmund.de
mailto:lig...@statistik.tu-dortmund.de



On 21.08.2011 10 tel:21.08.2011%2010:17, Eran Eidinger wrote:

Hello all,

I need to zoom in and out and travel(pan) inside a plot, like
you can do
on a Matlab plot.

If possible, I would also like the option to use the mouse to
set a marker
on the graph and get the (x,y) data for it, again, like in Matlab.



Don't know about that feature in Matlab, but see ?locator and
?identify for regular R graphics.

Uwe Ligges


Is this possible in R with the regular packages, or do you maybe
know a
different package that will allow this?

Eran.
*


*

[[alternative HTML version deleted]]


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




--
*
Eran Eidinger | Taykey Ltd | +972-54-5908077 | www.taykey.com
http://www.taykey.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] Dot plot with two grouping variables concurrently

2011-08-21 Thread markm0705
Dear R help(ers).  I'm an R-learner (about 10 hours now) trying to make a
ranked dot plot where the symbols are coded by two variables concurrently. 
I'm trying to use Deepanyan Sarkar's book 'Lattice' as a guide but get the
feeling it is a  bit advanced for my level of understanding.  

I have three questions

Q1. 

Right now I like to know how to get the dual coding working on the points on
a dotplot and also annotate these in a key.  Specifically I'm attempting to
code the fill of the points by a variable called 'Commodity' but would like
have different symbols to refelect a second variable called 'Year' (say
square, triangle and circle for different years).  

My code so far is as follows:

## initalise
library(lattice)

##read the data to a variable
Cal_dat - read.table(Calibration2.dat,header = TRUE,sep = \t,)

## set up plotting colours for the fills 
col.pat-c(violet,cyan,green,red,blue,black,yellow) 

##set up the plot key to be inside the plot
plot.key-list(
corner=c(1,0),
text=list(levels(Cal_dat$Commodity)),
title=Ore type,
points=list(pch=21,cex=1.3,fill=col.pat,col=black)
)   

##set some parameters for the dotplot
trellis.par.set(
dot.line=list(col = transparent),
axis.line=list(col = grey90),
axis.text=list(col =grey50, cex=0.8),
panel.background=list(col=grey98),
par.xlab.text= list(col=grey50)   
)

## Create the dot plot
dotplot(reorder(Mine, Resc_Gt)~ Resc_Gt,groups=Commodity,
  data=Cal_dat,
cex=1.2, 
pch=21,
aspect=2.0,
key=plot.key,
col=black,
fill=col.pat,
origin=0,
type = c(p, h),
main = Resource Tonnage,
xlab= tonnes (billions)   
)

The dot plot so far is attached as well as the input data.

Q2

I'm puzzled by the waring message (below) I get when runnin the current code
as follows (What does this mean and why does it occur).

Warning message:
In trellis.par.set(dot.line = list(col = transparent), axis.line =
list(col = grey90),  :
  Note: The default device has been opened to honour attempt to modify
trellis settings

Q3

Can anybody recommend a good 'starters' book for learning plotting in R that
is reasonably clear on the basics.  My primary interest is the graphing
tools that are in lattice (hence trying the Deepayan Sarkar book), but I'm
finding this guide rather tough going.

Thanks in advance - MarkM

http://r.789695.n4.nabble.com/file/n3758248/Calibration2.dat
Calibration2.dat 
http://r.789695.n4.nabble.com/file/n3758248/Ranked_boxplot_by_commodity.png
Ranked_boxplot_by_commodity.png 

--
View this message in context: 
http://r.789695.n4.nabble.com/Dot-plot-with-two-grouping-variables-concurrently-tp3758248p3758248.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] How can I divide an image and randomly plot the segements

2011-08-21 Thread Benson Kenduiywo

Hi! I would like to divide a 401 by 401 image into 20 equal blocks and then 
re-plot the image with the segments randomly distributed in it.
How can I do this?

.
Regards,
Kenduiywo Benson


[[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] Histogram from frequency data in pre-made bins

2011-08-21 Thread RobinLovelace
Dear R user,
I am using UK census data on travel to work. The authorities have provided a
breakdown in each area by mode (car, bicycle etc.) and distance travelled (0
– 2 km, 2 – 5 km etc). Therefore, after processing, the data for Sheffield
look like this https://files.one.ubuntu.com/ej2VtVbJTEaelvMRlsocRg :

dshef - read.table(distmodesheff.csv, sep=,, header=TRUE)
print(dshef)


  Dist  Tr Bici  Met  Pas  Foot   Bus   Car
1 245  571  491 2125 16644  4469 13494
2   2 – 5   80 1136 2540 4738  3659 17290 30212
3  5 – 10  217  466 2335 3994  1041 12963 35221
4 10 – 20  191   76  491 1333   332  2439 16322
5 20 – 30  1686   25  23541   175  3711
6 30 – 40   7863  1222074  2179
7  40 – 60 3496   21  26196   333  3501
8 60  332   62  125  369   534   433  3276
9Other 148   40   79  905   388   622  6481

It's interesting to look at the different distributions of different
transport modes: 

attach(dshef)
rs - rbind(Tr,Bici,Met,Pas,Foot,Bus,Car)

barplot(rs, beside=TRUE, names=Dist, col=rainbow(7), legend=TRUE)

http://r.789695.n4.nabble.com/file/n3758198/1.png 

This is brilliant, and creates output similar to that of OO calc:

http://r.789695.n4.nabble.com/file/n3758198/egraphmini.jpg 

However, as you can see, the pre-made categories (0 – 2 km etc.) are
unevenly spaced bins within a continuous variable. This puts the analysis
into histogram mode (with frequency determined by the area, not the height).
What I would look for for the vector Car, for example, would be something
like this: 

n - c(rep(1.5,Car[1]), rep(3,Car[2]), rep(7.7,Car[3]),
rep(15,Car[4]),rep(25,Car[5]), 

rep(35,Car[6]), rep(50,Car[7]), rep(100,Car[8]) )

hist(n, breaks=c(0,2,5,10,20,30,40,60,200))

http://r.789695.n4.nabble.com/file/n3758198/2.png 

This produces a histogram, but it's a tedious an ugly way of getting there.
Also, this does not allow for trend-line analysis of the likely distribution
of the continuous variable distance: lines(density(n)), for example results
in peaks around my arbitrary value.

Has anyone else encountered similar issues? I've searched high and low but
can find no solution other than creating a barplot with variable widths:
http://r.789695.n4.nabble.com/Histogram-using-frequency-data-td827927.html

Any ideas about how to resolve this issue very greatly appreciated.
Eventually I hope to model the distribution of distances travelled in order
to estimate the mean distance within each bin.

Many thanks, 

Robin


--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-from-frequency-data-in-pre-made-bins-tp3758198p3758198.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] How to navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Eran Eidinger
Thank you Uwe,

That solves the second question.
Still looking for some solution to zooming in and out dynamically.

Eran.
2011/8/21 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 21.08.2011 10:17, Eran Eidinger wrote:

 Hello all,

 I need to zoom in and out and travel(pan) inside a plot, like you can do
 on a Matlab plot.

 If possible, I would also like the option to use the mouse to set a marker
 on the graph and get the (x,y) data for it, again, like in Matlab.



 Don't know about that feature in Matlab, but see ?locator and ?identify for
 regular R graphics.

 Uwe Ligges


  Is this possible in R with the regular packages, or do you maybe know a
 different package that will allow this?

 Eran.
 *


 *

[[alternative HTML version deleted]]

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




-- 
*
Eran Eidinger | Taykey Ltd | +972-54-5908077 | www.taykey.com


*

[[alternative HTML version deleted]]

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


Re: [R] AFT model time-dependent with weibull distribution

2011-08-21 Thread JPF
thanks! 

--
View this message in context: 
http://r.789695.n4.nabble.com/AFT-model-time-dependent-with-weibull-distribution-tp3755079p3758267.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] Dot plot with two grouping variables concurrently

2011-08-21 Thread Weidong Gu
 Q1.

 Right now I like to know how to get the dual coding working on the points on
 a dotplot and also annotate these in a key.  Specifically I'm attempting to
 code the fill of the points by a variable called 'Commodity' but would like
 have different symbols to refelect a second variable called 'Year' (say
 square, triangle and circle for different years).

You can custumize pch as to reflect the levels of Year in both your
dotplot and key

my.pch- 1:length(levels(Cal_dat$Year)) ### for example

Then, use my.pch in the places of  pch in your codes of dotplot and key

HTH

Weidong Gu

 My code so far is as follows:

 ## initalise
 library(lattice)

 ##read the data to a variable
 Cal_dat - read.table(Calibration2.dat,header = TRUE,sep = \t,)

 ## set up plotting colours for the fills
 col.pat-c(violet,cyan,green,red,blue,black,yellow)

 ##set up the plot key to be inside the plot
 plot.key-list(
        corner=c(1,0),
        text=list(levels(Cal_dat$Commodity)),
        title=Ore type,
        points=list(pch=21,cex=1.3,fill=col.pat,col=black)
 )

 ##set some parameters for the dotplot
 trellis.par.set(
        dot.line=list(col = transparent),
        axis.line=list(col = grey90),
        axis.text=list(col =grey50, cex=0.8),
        panel.background=list(col=grey98),
        par.xlab.text= list(col=grey50)
 )

 ## Create the dot plot
 dotplot(reorder(Mine, Resc_Gt)~ Resc_Gt,groups=Commodity,
      data=Cal_dat,
        cex=1.2,
        pch=21,
        aspect=2.0,
        key=plot.key,
        col=black,
        fill=col.pat,
        origin=0,
        type = c(p, h),
        main = Resource Tonnage,
        xlab= tonnes (billions)
 )

 The dot plot so far is attached as well as the input data.

 Q2

 I'm puzzled by the waring message (below) I get when runnin the current code
 as follows (What does this mean and why does it occur).

 Warning message:
 In trellis.par.set(dot.line = list(col = transparent), axis.line =
 list(col = grey90),  :
  Note: The default device has been opened to honour attempt to modify
 trellis settings

 Q3

 Can anybody recommend a good 'starters' book for learning plotting in R that
 is reasonably clear on the basics.  My primary interest is the graphing
 tools that are in lattice (hence trying the Deepayan Sarkar book), but I'm
 finding this guide rather tough going.

 Thanks in advance - MarkM

 http://r.789695.n4.nabble.com/file/n3758248/Calibration2.dat
 Calibration2.dat
 http://r.789695.n4.nabble.com/file/n3758248/Ranked_boxplot_by_commodity.png
 Ranked_boxplot_by_commodity.png

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Dot-plot-with-two-grouping-variables-concurrently-tp3758248p3758248.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] Best way to setClass and setMethod for an R package?

2011-08-21 Thread Martin Morgan

On 08/21/2011 05:56 AM, Uwe Ligges wrote:



On 21.08.2011 00:48, Jonathan Greenberg wrote:

Folks:

I'm putting together an R package, and I was wondering where,
specifically, I put both class definitions (via setClass) as well as
setMethod calls? Is there a particular file name I need to use?


Hi Jonathan

In principle, S4 methods can dispatch on multiple classes, and an 
approach has been to have files AllClasses.R and AllGenerics.R to 
implement class and generic definitions, then foo-methods.R for methods 
defined on the generic foo. An 'advantage', for the lazy amongst us, is 
that this usually leads to a collation order that is appropriate -- 
class definition before use in method dispatch -- so that the Collates: 
field in the DESCRIPTION file does not have to be maintained.


In practice many S4 generics dispatch on a single argument and while 
there might be the equivalent of AllGenerics.R, the classes and their 
associated methods are defined in MyClass-methods.R.


Martin



No, any file name, e.g.
.../name_of_your_package/R/Name_of_your_class.R


Uwe Ligges




Thanks!

--j



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



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Henrique Dallazuanna
See setGraphicsEventHandlers function.

On Sun, Aug 21, 2011 at 10:04 AM, Eran Eidinger e...@taykey.com wrote:
 Thank you Uwe,

 That solves the second question.
 Still looking for some solution to zooming in and out dynamically.

 Eran.
 2011/8/21 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 21.08.2011 10:17, Eran Eidinger wrote:

 Hello all,

 I need to zoom in and out and travel(pan) inside a plot, like you can do
 on a Matlab plot.

 If possible, I would also like the option to use the mouse to set a marker
 on the graph and get the (x,y) data for it, again, like in Matlab.



 Don't know about that feature in Matlab, but see ?locator and ?identify for
 regular R graphics.

 Uwe Ligges


  Is this possible in R with the regular packages, or do you maybe know a
 different package that will allow this?

 Eran.
 *


 *

        [[alternative HTML version deleted]]

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




 --
 *
 Eran Eidinger | Taykey Ltd | +972-54-5908077 | www.taykey.com


 *

        [[alternative HTML version deleted]]

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 navigate (zoom, pan) in a plot/graph

2011-08-21 Thread Liviu Andronic
On Sun, Aug 21, 2011 at 3:04 PM, Eran Eidinger e...@taykey.com wrote:
 Thank you Uwe,

 That solves the second question.
 Still looking for some solution to zooming in and out dynamically.

Try package 'playwith'.
Liviu

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

2011-08-21 Thread David Winsemius


On Aug 21, 2011, at 7:03 AM, Salvo Mac wrote:


 I've   attached a sample of the data sets, this is my full code.

#R 2.13
#library(survival)
#library(Hmisc)
#library(splines)
library(rms)
train-as.data.frame( train-read.csv(G:\\train.txt, header=T,  
sep=\t))
test-as.data.frame( test-read.table(G:\\test.txt, header=T,  
sep=\t))

f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
val.surv(f.1, newdata=test, u=10)


#plot(calibrate(f.1, u=30, B=20))


Salvo;

I'm not sure where the error is coming from (although I will share my  
speculation below). I modified your code somewhat. I was under the  
impression that read.csv had sep=, hardcoded and the read.csv( ...  
seo=\t) would throw and error. The as.data.fame around either of the  
read.* statements is completely unnecessary:


Input code:
train-read.table(~/train.txt, header=T, sep=\t)
 test-read.table(~/test.txt, header=T, sep=\t)

I thought the  newdata=test argument should succeed, but it does throw  
the error that you report:


 f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
 val.surv(f.1, newdata=test, u=10)
Error in val.surv(f.1, newdata = test, u = 10) :
  dims [product 210] do not match the length of object [314]
In addition: Warning message:
In est.surv + S[, 1] :
  longer object length is not a multiple of shorter object length

I tried sampling from test with replacement to generate a dataframe of  
equal extent and with that object I do not get the same errors:


 extend - test[sample(1:nrow(test), 314, replace=TRUE), ]
  f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
 val.surv(f.1, newdata=extend, u=10)

Validation of Predicted Survival at Time= 10n= 314 , events= 64

hare fit:

dim A/D   loglik   AICpenalty
minmax
  1 Add   -485.24976.22  271.33 Inf
  2 Del   -349.57710.645.67  271.33
  3 Del   -346.74710.720.965.67
  4 Del   -346.26715.510.010.96
  5 Add   -346.25721.250.000.01

the present optimal number of dimensions is 2.
penalty(AIC) was 5.75, the default (BIC), would have been 5.75.

  dim1   dim2   betaSE Wald
Constant -10   0.55  -18.14
Time43  0.15  0.015   10.30

Function used to transform predictions:
function (p)  log(-log(p))

Mean absolute error in predicted probabilities: 0.0331
0.9 Quantile of absolute errors   : 0.0613

I have also tried looking at the code and adding   
options(error=utils::recover) to see if I can identify the point where  
the length mismatch is being generated, (but I am NOT an ace  
debugger). I can see that est.surv is created. I can also get the  
predict(fit, newdata, type = lp) call to run with train and give  
sensible numbers. You did not create (or at least say so) a datadist.  
I tried that when I saw that lim was dependent on datadist limits.


ddT - datadist(train); options(datadist=ddT)

Seeing the usehare was set to TRUE; I submitted the code section that  
was intended for that situation to a browser session and the the first  
line throws the error that I see at the console:


Enter a frame number, or 0 to exit

1: val.surv(f.1, newdata = test, u = 10)

Selection: 1
Called from: top level
Browse[1] i - !is.na(est.surv + S[, 1] + S[, 2])
Error during wrapup: dims [product 210] do not match the length of  
object [314]


As I read this that line is supposed to create an index of valid rows  
in newdata and the fitted values but is failing in the situation where  
the nrows of the newdata does not match that of the fit.


At this point one option might be trying to generate a structure that  
matches the val.surv output by going through the code and building it  
up bit by bit:


 w - structure(list(harefit = f, p = est.surv, actual = actual,
pseq = pseq, actualseq = actualseq, u = u, fun = fun,
n = nrow(S), d = sum(S[, 2]), units = units), class =  
val.survh)

return(w)

But a much better option would be to report the error to Frank  
Harrell. I'm copying him since I think your .txt files probably  
reached the list as well as my mailbox.


--
David.








From: David Winsemius dwinsem...@comcast.net
To: Salvo Mac salvo_...@yahoo.com
Cc: r-help@R-project.org r-help@r-project.org
Sent: Sunday, August 21, 2011 5:29 AM
Subject: Re: [R] val.surv


On Aug 20, 2011, at 10:25 PM, Salvo Mac wrote:

The test and train are like split data sets, contain similar  
variables but from different countries so the two sets are somehow   
independent. And yes it is a data frame.


What is a data.frame? test and train may be dataframes, but test[,  
age] is not a dataframe.



So I extracted age, time and event.


Code? The code you offered before would have created a newdata  
object (yes, a data.frame) with a single column bearing the same  
name as the vector argument , test1. Not named age. 

[R] Sweave doesn't work

2011-08-21 Thread danielepippo
Hi R users.

I've got a problem in producing the pdf file from Latex with R code. When I
run the code Sweave(example.Rtex) in R it seems working, but when I run
the Latex file it doesn't. The code error shown to me is below:
 
*Runaway argument?
{echo=FALSE}
data- read.csv(C:\\Users\\Daniele\\Desktop\\dati\\dati_england
! File ended while scanning use of \FV@BeginScanning.
inserted text 
\par 
* ...le/Desktop/dati/LaTeX1.Rtex*

The Sweave code in Latex is like this:

*\begin{Scode}{echo=FALSE}
data-
read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
\end{Scode}
\begin{figure}[!h]
\centering
\begin{Scode}{fig=TRUE, width=6, height=9, echo=FALSE}
data1=matrix(0,ncol=4,nrow=4)


\end{Scode}
\caption{Data}
\end{figure}*

I don't know how to fix this problem. Any advices?
Thanks very much

--
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-doesn-t-work-tp3758658p3758658.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] val.surv

2011-08-21 Thread Frank Harrell
I welcome a trivial self-contained set of code, not using frailties, that
generates its own data and which fails.  Then I'll debug.
Frank

David Winsemius wrote:
 
 On Aug 21, 2011, at 7:03 AM, Salvo Mac wrote:
 
  I've   attached a sample of the data sets, this is my full code.

 #R 2.13
 #library(survival)
 #library(Hmisc)
 #library(splines)
 library(rms)
 train-as.data.frame( train-read.csv(G:\\train.txt, header=T,  
 sep=\t))
 test-as.data.frame( test-read.table(G:\\test.txt, header=T,  
 sep=\t))
 f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
 val.surv(f.1, newdata=test, u=10)


 #plot(calibrate(f.1, u=30, B=20))
 
 Salvo;
 
 I'm not sure where the error is coming from (although I will share my  
 speculation below). I modified your code somewhat. I was under the  
 impression that read.csv had sep=, hardcoded and the read.csv( ...  
 seo=\t) would throw and error. The as.data.fame around either of the  
 read.* statements is completely unnecessary:
 
 Input code:
 train-read.table(~/train.txt, header=T, sep=\t)
   test-read.table(~/test.txt, header=T, sep=\t)
 
 I thought the  newdata=test argument should succeed, but it does throw  
 the error that you report:
 
   f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
   val.surv(f.1, newdata=test, u=10)
 Error in val.surv(f.1, newdata = test, u = 10) :
dims [product 210] do not match the length of object [314]
 In addition: Warning message:
 In est.surv + S[, 1] :
longer object length is not a multiple of shorter object length
 
 I tried sampling from test with replacement to generate a dataframe of  
 equal extent and with that object I do not get the same errors:
 
   extend - test[sample(1:nrow(test), 314, replace=TRUE), ]
f.1-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
   val.surv(f.1, newdata=extend, u=10)
 
 Validation of Predicted Survival at Time= 10  n= 314 , events= 64
 
 hare fit:
 
 dim A/D   loglik   AICpenalty
  minmax
1 Add   -485.24976.22  271.33 Inf
2 Del   -349.57710.645.67  271.33
3 Del   -346.74710.720.965.67
4 Del   -346.26715.510.010.96
5 Add   -346.25721.250.000.01
 
 the present optimal number of dimensions is 2.
 penalty(AIC) was 5.75, the default (BIC), would have been 5.75.
 
dim1   dim2   betaSE Wald
 Constant -10   0.55  -18.14
 Time43  0.15  0.015   10.30
 
 Function used to transform predictions:
 function (p)  log(-log(p))
 
 Mean absolute error in predicted probabilities: 0.0331
 0.9 Quantile of absolute errors   : 0.0613
 
 I have also tried looking at the code and adding   
 options(error=utils::recover) to see if I can identify the point where  
 the length mismatch is being generated, (but I am NOT an ace  
 debugger). I can see that est.surv is created. I can also get the  
 predict(fit, newdata, type = lp) call to run with train and give  
 sensible numbers. You did not create (or at least say so) a datadist.  
 I tried that when I saw that lim was dependent on datadist limits.
 
 ddT - datadist(train); options(datadist=ddT)
 
 Seeing the usehare was set to TRUE; I submitted the code section that  
 was intended for that situation to a browser session and the the first  
 line throws the error that I see at the console:
 
 Enter a frame number, or 0 to exit
 
 1: val.surv(f.1, newdata = test, u = 10)
 
 Selection: 1
 Called from: top level
 Browse[1] i - !is.na(est.surv + S[, 1] + S[, 2])
 Error during wrapup: dims [product 210] do not match the length of  
 object [314]
 
 As I read this that line is supposed to create an index of valid rows  
 in newdata and the fitted values but is failing in the situation where  
 the nrows of the newdata does not match that of the fit.
 
 At this point one option might be trying to generate a structure that  
 matches the val.surv output by going through the code and building it  
 up bit by bit:
 
   w - structure(list(harefit = f, p = est.surv, actual = actual,
  pseq = pseq, actualseq = actualseq, u = u, fun = fun,
  n = nrow(S), d = sum(S[, 2]), units = units), class =  
 val.survh)
  return(w)
 
 But a much better option would be to report the error to Frank  
 Harrell. I'm copying him since I think your .txt files probably  
 reached the list as well as my mailbox.
 
 -- 
 David.
 





 
 From: David Winsemius lt;dwinsem...@comcast.netgt;
 To: Salvo Mac lt;salvo_...@yahoo.comgt;
 Cc: r-help@R-project.org lt;r-help@r-project.orggt;
 Sent: Sunday, August 21, 2011 5:29 AM
 Subject: Re: [R] val.surv


 On Aug 20, 2011, at 10:25 PM, Salvo Mac wrote:

 The test and train are like split data sets, contain similar  
 variables but from different countries so the two sets are somehow   
 independent. And yes it is a data frame.

 What is a 

[R] rank analysis - reinventing the wheel?

2011-08-21 Thread Ben qant
Hello,

I have two data frames. One is my dependent variable and the other is my
independent variable. For each row I'd like to split the independent
variable into fractiles (25 or more) and calculate the average value of the
dependent variable. Then I would like to plot the average of the averages
for each row for each fractile.  If possible, I'd like to have the option to
1) define the fractiles independently for each row, and 2) define the
fractiles based off the independent variable data frame as a whole at the
start and keep it fixed.

Anyway, is there a pacakge/function in R that does something like this so I
don't have to reinvent the wheel? If not, any help on how to do this
efficiently in R would be great.

Here is a super simple example using 3 fractiles:

independent data frame:
  item1 item2 item3
1181516
2121217
3201318

dependent data frame:
  item1 item2 item3
1 3 1 6
2 2 2 7
3 1 3 8

fractiles by row by item: (done with independent data frame, redefining
fractiles each row)
fractiles:  12   3
row 1item2 item3   item1  (because 15  16  18)
row 2item1,item2[none]  item3  (because 12  17 ... or however ties
are handled is fine)
row 3item2 item3   item1  (because 13  18  20)

Note: in the above fractiles there would almost always be more than one item
in each fractile if this example wasn't so simple...

dependent variable averages by row by fractile:
fractiles:  12   3
row 1   1   63
row 2   2   [none] 7
row 3   3   8 1

Note: obviously this example is so simple there aren't actual averages
because there aren't enough items for each fractile, but I hope you get the
point.

So then the averages of the fractiles would be:
fractiles:   12   3
dependent data avg:   2   73.67

Then I would like to plot a histogram of the fractile averages directly
above.

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.


Re: [R] Raw epoch time from XTS

2011-08-21 Thread Noah Silverman
Josh,

Good point about including an example.

calling xcoredata() does work, but only for a *single* row of the data at a 
time.  In R, I'm used to passing an entire data structure or vector to a 
function and automatically getting back a vector of all the results.  In this 
case, it doesn't work that way.

The attr() function is probably the best solution.

Thanks!

--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095

On Aug 20, 2011, at 1:03 AM, Joshua Wiley wrote:

 Hi Noah,
 
 This is one of those cases where following the posting guide
 (particularly the minimal, reproducible example part) would have
 really helped.  Are you saying that calling:
 xcoredata(your_xts_object) does not give you the internal
 representation of time that you want?
 
 data(sample_matrix)
 sample.xts - as.xts(sample_matrix, descr='my new xts object')
 # returns a list, the index is the numeric representation of time
 displayed in the rows
 xcoredata(sample.xts)
 
 You could also try the more direct:
 
 attr(xts_object, index)
 
 If this is not what you want or is not working for you, providing us
 the output of dput() from the first few rows of your dataset and an
 example of what you do want would be spectacular.
 
 Cheers,
 
 Josh
 
 On Sat, Aug 20, 2011 at 12:44 AM, Noah Silverman noahsilver...@ucla.edu 
 wrote:
 Hi,
 
 I have a very large data set stored as an xts object.
 
 xts is very nice about showing row labels as human readable dates and 
 times.
 
 I want the actual epoch values that are stored internally.  The only way I 
 can find to access them is one-at-a-time using the internal function: 
 xcoredata()
 
 Calling this in an entire column, the R way doesn't work.  It will only 
 return a single value.  Calling it in a loop for each row works but is 
 painfully slow.
 
 Since the epoch is stored internally, there must be some way to just grab it 
 as a vector.  Does anyone know how?
 
 Thanks!
 
 --
 Noah Silverman
 UCLA Department of Statistics
 8117 Math Sciences Building
 Los Angeles, CA 90095
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Joshua Wiley
 Ph.D. Student, Health Psychology
 Programmer Analyst II, ATS Statistical Consulting Group
 University of California, Los Angeles
 https://joshuawiley.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] Compile on Fedora

2011-08-21 Thread Noah Silverman
Hi,

I want to create a custom build of R, for my particular machine that will run 
as fast as possible. 

CPU: Dual cora AMD 64 bit  

OS: Fedora 15

I know there are a lot of options for compile time flags, lapack, blas, atlas, 
etc.  Not sure what the best combination is.  

Has someone already worked this out? 

Thanks!


--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095

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

2011-08-21 Thread Peter Langfelder
On Sun, Aug 21, 2011 at 10:18 AM, Noah Silverman noahsilver...@ucla.edu wrote:
 Hi,

 I want to create a custom build of R, for my particular machine that will run 
 as fast as possible.

 CPU: Dual cora AMD 64 bit

 OS: Fedora 15

 I know there are a lot of options for compile time flags, lapack, blas, 
 atlas, etc.  Not sure what the best combination is.

If you need any kind of matrix manipulations with larger matrices (say
more than a few hundred rows or columns), I would definitely suggest a
custom BLAS, for example Goto BLAS or ATLAS. When I last compared them
a couple of years ago, Goto BLAS was somewhat (on the order of 20%)
faster than ATLAS. This may have changed because of better compilers,
plus I only used Intel processors, so you may want to look into that.
A problem with Goto BLAS was that it would inexplicably slow down, or
grind to a halt, if two separate R processes were calling the BLAS
routines at the same time, whereas ATLAS never gave us any trouble.

My understanding is that Goto BLAS is not maintained anymore but the
existing version should work well.

HTH,

Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rank analysis - reinventing the wheel?

2011-08-21 Thread Frank Harrell
This is close: require(Hmisc); ?xYplot and see method='quantile'
Frank

Ben qant wrote:
 
 Hello,
 
 I have two data frames. One is my dependent variable and the other is my
 independent variable. For each row I'd like to split the independent
 variable into fractiles (25 or more) and calculate the average value of
 the
 dependent variable. Then I would like to plot the average of the averages
 for each row for each fractile.  If possible, I'd like to have the option
 to
 1) define the fractiles independently for each row, and 2) define the
 fractiles based off the independent variable data frame as a whole at the
 start and keep it fixed.
 
 Anyway, is there a pacakge/function in R that does something like this so
 I
 don't have to reinvent the wheel? If not, any help on how to do this
 efficiently in R would be great.
 
 Here is a super simple example using 3 fractiles:
 
 independent data frame:
   item1 item2 item3
 1181516
 2121217
 3201318
 
 dependent data frame:
   item1 item2 item3
 1 3 1 6
 2 2 2 7
 3 1 3 8
 
 fractiles by row by item: (done with independent data frame, redefining
 fractiles each row)
 fractiles:  12   3
 row 1item2 item3   item1  (because 15  16  18)
 row 2item1,item2[none]  item3  (because 12  17 ... or however
 ties
 are handled is fine)
 row 3item2 item3   item1  (because 13  18  20)
 
 Note: in the above fractiles there would almost always be more than one
 item
 in each fractile if this example wasn't so simple...
 
 dependent variable averages by row by fractile:
 fractiles:  12   3
 row 1   1   63
 row 2   2   [none] 7
 row 3   3   8 1
 
 Note: obviously this example is so simple there aren't actual averages
 because there aren't enough items for each fractile, but I hope you get
 the
 point.
 
 So then the averages of the fractiles would be:
 fractiles:   12   3
 dependent data avg:   2   73.67
 
 Then I would like to plot a histogram of the fractile averages directly
 above.
 
 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.
 


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/rank-analysis-reinventing-the-wheel-tp3758729p3758906.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] Raw epoch time from XTS

2011-08-21 Thread Joshua Wiley
Noah,

For me xcoredata() returns a vector of the results, which makes me
wonder if you are using an old version of R or your data is somehow
stored differently.

Cheers,

Josh

On Sun, Aug 21, 2011 at 10:15 AM, Noah Silverman noahsilver...@ucla.edu wrote:
 Josh,

 Good point about including an example.

 calling xcoredata() does work, but only for a *single* row of the data at a 
 time.  In R, I'm used to passing an entire data structure or vector to a 
 function and automatically getting back a vector of all the results.  In this 
 case, it doesn't work that way.

 The attr() function is probably the best solution.

 Thanks!

 --
 Noah Silverman
 UCLA Department of Statistics
 8117 Math Sciences Building
 Los Angeles, CA 90095

 On Aug 20, 2011, at 1:03 AM, Joshua Wiley wrote:

 Hi Noah,

 This is one of those cases where following the posting guide
 (particularly the minimal, reproducible example part) would have
 really helped.  Are you saying that calling:
 xcoredata(your_xts_object) does not give you the internal
 representation of time that you want?

 data(sample_matrix)
 sample.xts - as.xts(sample_matrix, descr='my new xts object')
 # returns a list, the index is the numeric representation of time
 displayed in the rows
 xcoredata(sample.xts)

 You could also try the more direct:

 attr(xts_object, index)

 If this is not what you want or is not working for you, providing us
 the output of dput() from the first few rows of your dataset and an
 example of what you do want would be spectacular.

 Cheers,

 Josh

 On Sat, Aug 20, 2011 at 12:44 AM, Noah Silverman noahsilver...@ucla.edu 
 wrote:
 Hi,

 I have a very large data set stored as an xts object.

 xts is very nice about showing row labels as human readable dates and 
 times.

 I want the actual epoch values that are stored internally.  The only way I 
 can find to access them is one-at-a-time using the internal function: 
 xcoredata()

 Calling this in an entire column, the R way doesn't work.  It will only 
 return a single value.  Calling it in a loop for each row works but is 
 painfully slow.

 Since the epoch is stored internally, there must be some way to just grab 
 it as a vector.  Does anyone know how?

 Thanks!

 --
 Noah Silverman
 UCLA Department of Statistics
 8117 Math Sciences Building
 Los Angeles, CA 90095

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




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 Programmer Analyst II, ATS Statistical Consulting Group
 University of California, Los Angeles
 https://joshuawiley.com/





-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.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] Sweave doesn't work

2011-08-21 Thread Joshua Wiley
Hi,

You would probably be better off providing us with the code you weave
rather than the TeX code.  Also, the problem is quite possibly not
near where the error occurred.  In my (admittedly limited) experience,
runaway argument issues tend to mean at some earlier point I:

A) did not choose the right environment
B) did not close an environment
C) did not properly escape something leading essentially to A or B

Something seems weird to me with the LaTeX code you show though.  In
addition to posting your code (not the TeX output), it would also be
good to post your version of R.

Cheers,

Josh


On Sun, Aug 21, 2011 at 9:18 AM, danielepippo dan...@hotmail.it wrote:
 Hi R users.

 I've got a problem in producing the pdf file from Latex with R code. When I
 run the code Sweave(example.Rtex) in R it seems working, but when I run
 the Latex file it doesn't. The code error shown to me is below:

 *Runaway argument?
 {echo=FALSE}
 data- read.csv(C:\\Users\\Daniele\\Desktop\\dati\\dati_england
 ! File ended while scanning use of \FV@BeginScanning.
 inserted text
                \par
 * ...le/Desktop/dati/LaTeX1.Rtex*

 The Sweave code in Latex is like this:

 *\begin{Scode}{echo=FALSE}
 data-
 read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
 \end{Scode}
 \begin{figure}[!h]
 \centering
 \begin{Scode}{fig=TRUE, width=6, height=9, echo=FALSE}
 data1=matrix(0,ncol=4,nrow=4)
 
 
 \end{Scode}
 \caption{Data}
 \end{figure}*

 I don't know how to fix this problem. Any advices?
 Thanks very much

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Sweave-doesn-t-work-tp3758658p3758658.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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.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] Compile on Fedora

2011-08-21 Thread Dirk Eddelbuettel

On 21 August 2011 at 10:18, Noah Silverman wrote:
| Hi,
| 
| I want to create a custom build of R, for my particular machine that will run 
as fast as possible. 
| 
| CPU: Dual cora AMD 64 bit  
| 
| OS: Fedora 15
| 
| I know there are a lot of options for compile time flags, lapack, blas, 
atlas, etc.  Not sure what the best combination is.  
| 
| Has someone already worked this out? 

Please the fine manual at

http://cran.r-project.org/doc/manuals/R-admin.html#Configuration-on-a-Unix_002dalike

Dirk

-- 
Two new Rcpp master classes for R and C++ integration scheduled for 
New York (Sep 24) and San Francisco (Oct 8), more details are at
http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10
http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] trouble installing packages on OpenSuse 11.4

2011-08-21 Thread Steven Kennedy
I have similar problems when trying to install packages while at work.
It might have something to do with your firewall settings.


On Wed, Aug 17, 2011 at 4:38 AM, Dinesh din...@milkorwater.com wrote:
 Hi,

 I am trying to install a bunch of packages via command line and can use
 some help in getting it right. My env is a freshly setup OpenSuse 11.4
 on an amd desktop. I have not yet installed gcc (Will I need gcc to
 install packages? I have installed make, assuming R might need it.). I
 have tried it both under R2.12 and R2.13. I have a list of packages to
 install such as fImport, fGarch, zoo, and several more. I am logged in
 as root because I want the packages to be visible to all users

 a) R CMD INSTALL fImport
 This produces no results.

 b) sudo R CMD INSTALL fImport
 This downloads timeDate and gets stuck there. (I did sudo based on my
 experience on Win7 where I had to start R as administrator to update the
 common package library regardless of how I was logged in.)

 c) R
 then,
 install.packages( fImport, repo=|http://cran.r-project.org; );
 If I executed via command R then it furnishes a listbox of mirrors, I
 select a mirror and then it hangs. If I executed via command sudo R
 then it furnishes a 24x80 style (not tk) list of choices, I select a
 mirror and then it hangs.

 I will appreciate your help in figuring this out. Ideally,  I would
 ideally to run R CMD INSTALL or R CMD BATCH with a short command file so
 that I can configure a new machine via a script.

 I also tried to download the tarballs - but then figuring out all the
 dependencies gets very messy. Besides, that would be, like, reinventing
 the wheel!

 |--
 --

 Regards,
 Dinesh K. Somani
 --
 /Improving Your Odds/


        [[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] Split split plot analysis for unbalanced data using lmer

2011-08-21 Thread Stephen Gosnell
Hello,

I'm attempting to analyze a split-split plot model, currently using
lmer.  My design is similar to that used in Casella's Experimental
Designs Ozone Example (example 5.7, p 197), but I have been unable to
find any coding help for split-split plot models through searches of
several textbooks and the R list serve. I have three treatments of
interest (A,B,C), each with 2 treatment levels.  One level of
treatment A (Y or N) was applied to 6 blocks (Block, labelled
1,2,3,4,5,6).  Each block was
subdivided into 4 subplots (Positon, labelled 1,2,3,4, so implicit nesting may
be a problem), to which treatment B (Y or N) was randomly assigned (2
replicates of each level of treatment B per block).  Each of these
subplots was divided in half and randomly assigned treatment C (B or
M).  My response variable is the number of predetermined spots (out of
132) occupied by a certain species; I have a unbalanced data set since
one observation was not recorded for a total of 47 counts. My data is
set up as:

  Block A Position B C Count
1 1 Y4 N B64
2 1 Y4 N M   109
3 1 Y3 Y M88
4 1 Y3 Y B 0
5 1 Y1 Y B47
6 1 Y1 Y M91

with both position and block set to factors, not integers.

My current model is:

model=lmer(cbind(june$Count,
132-june$Count)~A*B*C+(1|A/B)+(1|Block),june, family=binomial)

with the resulting summary

 model
Generalized linear mixed model fit by the Laplace approximation
Formula: cbind(june$Count, 132 - june$Count) ~ A * B * C + (1 | A/B) +
(1 | Block)
  Data: june
  AIC   BIC logLik deviance
 806.9 827.2 -392.4784.9
Random effects:
 Groups NameVariance Std.Dev.
 Block  (Intercept) 0.074222 0.27244
 B:A(Intercept) 0.00 0.0
 A  (Intercept) 0.00 0.0
Number of obs: 47, groups: Block, 6; B:A, 4; A, 2

Fixed effects:
   Estimate Std. Error z value Pr(|z|)
(Intercept) -0.094520.17295  -0.547  0.58470
AY   0.237560.24453   0.971  0.33130
BY  -0.309490.10259  -3.017  0.00255 **
CM  -0.574380.10434  -5.505 3.70e-08 ***
AY:BY0.649310.14922   4.351 1.35e-05 ***
AY:CM1.122200.14754   7.606 2.83e-14 ***
BY:CM0.394170.14769   2.669  0.00761 **
AY:BY:CM-0.450400.21368  -2.108  0.03504 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) AY BY CM AY:BY  AY:CM  BY:CM
AY   -0.707
BY   -0.291  0.206
CM   -0.286  0.202  0.483
AY:BY 0.200 -0.283 -0.688 -0.332
AY:CM 0.202 -0.286 -0.342 -0.707  0.469
BY:CM 0.202 -0.143 -0.695 -0.706  0.478  0.500
AY:BY:CM -0.140  0.197  0.480  0.488 -0.698 -0.691 -0.691

I'm not sure if I have specified the model correctly (should Position
be included in the model specification  as well?) or how to interpret
the results.  I think the group numbers for blocks and A are correct,
but I'm not sure how B:A should be checked or if the implicit nesting
of B is a problem.  Do I need to include factor C in my nesting
structure (even though its the lowest level)?  My initial conclusions
are that Treatments B and C have a main effect and higher order
interactions suggest treatment A is also important.  All my random
effects also seem extremely small, which seems concerning.

Any help (or pertinent references) for model setup or interpretation
is greatly appreciated.

Stephen Gosnell
Department of Ecology, Evolution, and Marine Biology, UCSB

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


Re: [R] Sweave doesn't work

2011-08-21 Thread Philipp Pagel
On Sun, Aug 21, 2011 at 09:18:25AM -0700, danielepippo wrote:

 Sweave(example.Rtex) in R it seems working

[...]

 * ...le/Desktop/dati/LaTeX1.Rtex*

Sounds like you are first running sweave on the file 'example.Rtex'
and later LaTex on 'LaTeX1.Rtex'

Two points:

1) why do these files have totally differnt names? If the Sweave file
was called 'example.Rtex' I'd expect the corresponding LaTex file to
be 'example.tex'

2) Why to both files have the same extension? Commonly, the Sweave
files are called 'something.Snw' or 'something.Rnw' and the resulting
LaTex Files would be 'something.tex'

cu
Philipp

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] pooled hazard model with aftreg and time-dependent variables

2011-08-21 Thread JPF
Dear R-users,

I have two samples with individuals that are in more than one of the samples
and individuals that are only in one sample. I have been trying to do  a
pooled hazard model, stacking one sample below the other, with aftreg and
time-dependent covariates. The idea behind is to see aggregate effects of
covariates, but need to control for ther effects of same individuals in both
samples and the samples themselves.  


 I created two variables for this purpose: a variable representing
individuals, as a factor, and a variable for each sample, and included them
in the model. I provide an example below. 

If I include the factor sample the analysis works. If I include both sample
+ individual like this: 

 weibullaft-aftreg(Surv(sta,time,S) ~ TDC1 + TIC1 + sample + individual,
 dist=weibull, 
 data.frame=Data, id=ID) 

, it appears an error with aftreg saying: 

Error in solve.default(fit$hessian) : 
  Lapack routine dgesv: system is exactly singular

With phreg the error is: 

fail in [dsytrf]; info = 14


1 - I am probably doing something wrong. Any suggestion to control for
individuals too would be highly appreciated.

2 - Is including  factor(sample) enough to control for the samples?


Data 
   S sta time  TDC1 total_time TIC1  ID   sample individual 
A 1   0   1  48.50   1  1   1   1   
 
1
B 0   0   1  65.96   2   1   2   1  
  
2
B 1   1   2  65.08   2  121 
 
2
C 0   0   1  0.002   4   3 1
  
3
C 1   1   2  0.002   4   3 1
 
3
D 0   0   1 72.742   5   41 
 
4
D 1   1   2 72.522   5   4 1
  
4
E 0   0   1 61.84 2  351
  
5
E 0   1   2 60.562   351
  
5
F 0   0   1 35.044   261
  
6
F 0   1   2 36.974   261
  
6
F 0   2   3 37.924   26   1 
   
6 
F 1   3   4 39.014   261
   
6

G 0   0   1  15.96   2   4   7 2
   
7
G 1   1   2  15.08   2  47 2
   
7
H 0   0   1 33.042   282
   
8
H 0   1   2 39.972   282
   
8 
D 0   0   1 75-342   5   92 
   
4
D 0   1   2 76.992   5   9  2   

4
E 0   0   1 70.45 2  3102   
   
5
E 1   1   2 45.012   3102   
   
5
F 0   0   1 35.044   2112   
   
6
F 1   1   2 36.974   2112   
   
6


time - time to event 
sta - starting time 
TDC - time dependent covariates 
TIC - time independent covariate 
total_time - total time at risk 
ID - ID 
Individual - as.factor code for individual 
Sample - as.factor code for sample


thanks,

J


--
View this message in context: 
http://r.789695.n4.nabble.com/pooled-hazard-model-with-aftreg-and-time-dependent-variables-tp3758805p3758805.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 message: object of type 'closure' is not subsettable

2011-08-21 Thread Newbie
Thank you for your help, even though there was such an obvious mistake, Im
sorry for that
I have now tried to incorporate your suggested solution, but just as last
time (the other post that you referred to), I get the values of the initial
parameters when I run nlminb. 
I have changed the code a bit, see below, due to some error messages. 
Can anyone see what I am doing wrong? 

Thank you in advance!

http://r.789695.n4.nabble.com/file/n3758834/S%26P_500_calls%2C_jan-jun_2010.csv
S%26P_500_calls%2C_jan-jun_2010.csv 

setwd(F:/Data til speciale/)

## Calibration of Heston model parameters


marketdata - read.csv(file=SP 500 calls, jan-jun 2010.csv, header=TRUE,
sep=;)

BS_Call - function(S0, K, T, r, sigma, q)
{
sig - sigma * sqrt(T)
d1 - (log (S0/K) + (r - q + sigma^2/2) * T ) / sig
d2 - d1 - sig
Presentvalue - exp(-r*T)
return (S0 * exp(-q*T) * pnorm(d1) - K*Presentvalue*pnorm(d2))
}


#- Values --
 Data imported
S0 - 1136.02
X - marketdata[1:460,9]
t - marketdata[1:460,17]/365   #Notice the T is measured in years now
implvol - marketdata[1:460,12]

k - log(X/(S0*exp(r-q)*t))

## Initial values
kappa - 0.0663227  # Lambda = -kappa
rho - -0.6678461
eta - 0.002124704
theta - 0.0001421415
v0 - 0.0001421415

q - 0.02145608
r - 0.01268737

#-
 The price of a Call option (Eq. (5.6) of The Volatility Surface,
Gatheral)
# In terms of log moneyness

Price_call - function(phi, k, t)
{
integrand -  function(u) {Re(exp(-1i*u*k)*phi(u - 1i/2, t)/(u^2 + 
1/4))}
res - S0*exp(-q*t) -
exp(k/2)/pi*integrate(Vectorize(integrand),lower=0,upper=Inf,
subdivisions=460)$value
return(res)
}


# The characteric formula for the Heston model (Eq. XX)
phiHeston - function(kappa, rho, eta, theta, v0)
{   
lambda - -kappa
function(u, t)
{
alpha - -u*u/2 - 1i*u/2
beta - lambda - rho*eta*1i*u   
gamma - eta^2/2
d - sqrt(beta*beta - 4*alpha*gamma)
rplus - (beta + d)/(eta^2)
rminus - (beta - d)/(eta^2)
g - rminus / rplus
D - rminus * (1 - exp(-d*t))/ (1 - g*exp(-d*t))
C - lambda* (rminus * t - 2/eta^2 * log( (1 - 
g*exp(-(d*t)))/(1 - g)) )
return(exp(C*theta + D*v0))
}
}

## Calculating the Heston model price with fourier
HestonCall-function(k,t)
{
res-Price_call(phiHeston(kappa, rho, eta, theta, v0),k,t)
return(res)
}


# Vectorizing the function to handle vectors of strikes and maturities
HestonCallVec - function(k,t)
{
mapply (HestonCall, k, t)
}

lb - c(0, -0.9, 0, 0, 0)
ub - c(100, 0.9, 0.5, 1, 1)
#BS_Call(S0, exp(k), t, r, implvol, q)

difference - function(k, t, S0, r, implvol, q, kappa, rho, eta, theta, v0)
{
return(HestonCallVec(k,t) - BS_Call(S0, exp(k), t, r, implvol, q))
}
difference(k,t,S0, r, implvol, q, kappa, rho, eta, theta, v0)
y - function(par) {kappahat-par[1]; rhohat-par[2]; etahat-par[3];
thetahat-par[4]; v0hat-par[5]; sum(difference(k, t, S0, r, implvol, q,
kappahat, rhohat, etahat, thetahat, v0hat)^2)}
nlminb(start=c(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper
=ub)

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-not-subsettable-tp3752886p3758834.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] Increase the size of the boxes but not the text in a legend

2011-08-21 Thread Jürgen Biedermann

HI there,

I want to add a legend to a plot using the density and angle argument, 
so patterns with lines in different angles are used in the plot and 
should be referred to.

When I use default settings, the filled boxes are too small.
With the cex argument I can enlarge the whole legend, but then the text 
gets too big.


How could I just increase the size of the single boxes and not the text.

I tried:

legend(topright, c(Trefferquote,Falschalarmquote), 
density=c(20,16), angle=c(45,0),cex=1.5, y.intersp=0.8)


The sizes of the boxes are good now, but the text is too large and so 
also the whole legend box gets too big.


Thank you very much for your help
Jürgen

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

2011-08-21 Thread Andrey A
I have a plot and my x axis is Time in days, I need to shift it by +15 days,
how do i do it?
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.


Re: [R] Time series plot shift

2011-08-21 Thread R. Michael Weylandt michael.weyla...@gmail.com
Depending on the time series object you are using, the lag() function will do 
it. Read the documentation ?lag for details on your specific ts class. 

Michael Weylandt

On Aug 21, 2011, at 3:04 PM, Andrey A ava...@gmail.com wrote:

 I have a plot and my x axis is Time in days, I need to shift it by +15 days,
 how do i do it?
 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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple R linear models into one Latex table

2011-08-21 Thread Alex Ruiz Euler


Dear community,

I had been looking for an easy way to produce latex tables from R
output. xtable() and the package apsrtable produce good outputs but they are not
exactly what I was looking for. 

I wrote this code that generates regression tables from multiple R
linear models. I want to share it because it might be
useful for someone else, and because I would appreciate comments on how to
optimize the code. I'm also open to suggestions about design or packages to 
include. Or pointing out bugs. I hope this is the right list to post.

Please consider it is still in a very primitive form, and the generated table 
might look strange for some disciplines (I come from political science).

Thanks,
Alex



## Start script


#
 R models to Latex table 
#


# nice() - Multiple R linear models into one Latex table.
#
#nice(list(fit1,fit2,...,fitn)) for generic table with n models
#
#   or
#
#  for better tables, create objects 'model.names' and 'final.varnames', then
#
#nice(list(fit1,fit2,...,fitn), model.names, final.varnames)



nice - function(modelos, model.names=NULL, final.varnames=NULL) {

  var.names-vector(mode=character)
  k-1
  for (i in 1:length(modelos)) {
l-length(names(coef(modelos[[i]])))
var.names[c(k:c(k+l-1))]-names(coef(modelos[[i]]))
k-k+l
  }
  var.names-unique(var.names)

  if(is.null(final.varnames)) {
  final.varnames-var.names
  }

  if(is.null(model.names)) {
  model.names-paste(Model,1:length(modelos))
  }

  mat.all-matrix(data=NA, nrow=length(var.names)*2, byrow=FALSE, 
ncol=length(model.names), 
dimnames=list(c(rep(c(coef,sd),length=length(var.names)*2)), 
c(model.names)))
  dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], by=2))]-var.names; 
dimnames(mat.all)[[1]][c(seq(2,dim(mat.all)[1], by=2))]-

  for (j in 1:length(modelos)) {

mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])),j]-coef(modelos[[j]])

mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])+1),j]-sqrt(diag(vcov(modelos[[j]])))
  }

  mat.all-signif(mat.all, digits=3); 
dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], by=2))]-final.varnames


  cat(\\begin{table}[!hbt], \n,\\caption[Short for List of Tables]{Long 
for this 
title},\n,\\begin{center},\n,\\begin{tabular}{ll},\n)
  
cat(,paste(model.names[1:length(model.names)-1],),model.names[length(model.names)],,\n,\\hline,\n)
  for(i in 1:dim(mat.all)[1]) {
if(i %in% c(seq(1,dim(mat.all)[1], by=2))) { # Odd rows (coefficients)
  
  cat(dimnames(mat.all)[[1]][i],)
  cat(
for (j in 1:(length(modelos)-1)) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
  } else cat(round(mat.all[i,j], digits=5),)
} else cat()
  })
  
  cat(
for (j in length(modelos) ) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
} else cat(round(mat.all[i,j], digits=5))
}
   })
  cat(, \n )

  } else {
  
cat(,ifelse(!is.na(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)]),paste((\\emph{,round(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)],
 digits=5),}),sep=), paste()),
   
ifelse(!is.na(mat.all[i,length(dimnames(mat.all)[[2]])]),paste((\\emph{,round(mat.all[i,length(dimnames(mat.all)[[2]])],
 digits=5),}),sep=),paste( )),
, sep=, fill=TRUE)}
}
  
  cat(\\hline,\n,\\emph{n},)
  cat(
  for(j in 1:(length(modelos)-1)) {
cat(length(modelos[[j]]$residuals),,sep=)
  },
  for(j in length(modelos)) {
cat(length(modelos[[j]]$residuals), , \n, sep=)
  }
  )
  
  cat(\\emph{Adj-R$^2$})
  cat(
for(j in 1:(length(modelos)-1)) {
if (class(modelos[[j]])[1]==lm) 
{cat(round(summary(modelos[[j]])$adj.r.squared,digits=2),, sep=)} else {
cat() 
}
  },
  for(j in length(modelos)) {
if (class(modelos[[j]])[1]==lm) 
{cat(round(summary(modelos[[j]])$adj.r.squared,digits=2),,\n)} else {
cat(,\n) 
}
  } 
)

  cat(\\emph{AIC})
  cat(
for(j in 1:(length(modelos)-1)) {
if (class(modelos[[j]])[1]==glm) 
{cat(round(summary(modelos[[j]])$aic, digits=0),, sep=)} else {
cat()
}
  },
  for(j in length(modelos)) {
if 

[R] Changing data scales

2011-08-21 Thread Jim Silverton
I have data that ranges from 0.3 to 2 and I want to change the scale to be
from 0 to 1.
Can this be done in R?

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


Re: [R] Changing data scales

2011-08-21 Thread Jorge I Velez

On 8/21/11 8:04 PM, Jim Silverton wrote:

I have data that ranges from 0.3 to 2 and I want to change the scale to be
from 0 to 1.
Can this be done in R?


Take a look at ?scale

HTH,
Jorge

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

2011-08-21 Thread Brad Patrick Schneid
these guys wont help you with your homework.  But have you ever heard of
Google?... if so, R has plenty of online manuals and cheat sheets.

--
View this message in context: 
http://r.789695.n4.nabble.com/Quadratic-equation-tp3758790p3759239.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] How can I divide an image and randomly plot the segements

2011-08-21 Thread Rolf Turner

On 21/08/11 23:06, Benson Kenduiywo wrote:

Hi! I would like to divide a 401 by 401 image into 20 equal blocks and then 
re-plot the image with the segments randomly distributed in it.
How can I do this?


For a 401 x 401 pixellation --- I don't know.  If you use a 400 x 400 
pixellation,

then the class im in the spatstat package can be used via the attached
function shuffleIm().  The number of pixels in each dimension must be 
divisible
by the number of blocks into which that dimension is subdivided.   E.g. 
if you
create your 20 blocks by making 4 divisions in the x-direction and 5 
divisions in
the y-direction then the number of pixels in the x-direction must be 
divisible by 4
and the number in the y-direction must be divisible by 5.  Since 401 is 
prime

it's kind of hard to do any kind of subdividing with a 401 x 401 image.

Note that if X is an object of class im with a 401 x 401 pixellation, 
you can

convert it to one with a 400 x 400 pixellation via

X - as.im(X,dimyx=400)

This makes the pixel values of the new image equal to the values of the old
image at the closest pixel centre.  This shouldn't (???) cause too much 
distortion.

Said he, optimistically.  (In the one experiment that I did, the images were
visually indistinguishable.)

If you have a 400 x 400 pixel image, say X, of class im then

Y - shuffleIm(X,nx=4,ny=5)

gives you a new image in which the matrix of pixel values has been 
subdivided into
a 5 x 4 array of 80 x 100 submatrices and these submatrices randomly 
shuffled.
(Note that the rows of the matrix of pixel values in an object of class 
im correspond
to the ***y*** direction and the columns correspond to the ***x*** 
direction.

See fortune(conventions) for a comment. :-) )

Hope this does what you want.

cheers,

Rolf Turner
shuffleIm - function (X,nx,ny) {
verifyclass(X,im)
ddd - dim(X)
if(ddd[1]%%ny != 0) stop(Argument \ny\ must divide first dimension of 
image.\n)
if(ddd[2]%%nx != 0) stop(Argument \nx\ must divide second dimension of 
image.\n)
ky - ddd[1]/ny
kx - ddd[2]/nx
n  - nx*ny
ind - sample(1:n,n)
V - matrix(NA,ddd[1],ddd[2])
for(k in 1:n) {
j  - k%%nx
if(j==0) j - nx
i  - (k-j)/nx + 1
j1 - (j-1)*kx + 1:kx
i1 - (i-1)*ky + 1:ky
kr - ind[k]
j  - kr%%nx
if(j==0) j - nx
i  - (kr-j)/nx + 1
j2 - (j-1)*kx + 1:kx
i2 - (i-1)*ky + 1:ky
V[i1,j1] - X$v[i2,j2]
}
X$v - V
X}
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Changing data scales

2011-08-21 Thread Joshua Wiley
On Sun, Aug 21, 2011 at 5:50 PM, Jorge I Velez jorgeivanve...@gmail.com wrote:
 On 8/21/11 8:04 PM, Jim Silverton wrote:

 I have data that ranges from 0.3 to 2 and I want to change the scale to be
 from 0 to 1.
 Can this be done in R?

 Take a look at ?scale

Which leads one to:

scale(x, .3, 1.7)

but this is far from the only possible way.  Another possibility would be:

f - function(x) ifelse(x  0, (1/(2 - x)), (1 - 1/(2 + x)))

finv - function(y) ifelse((0  y)  (y  .5), (2 - (1/y)), (1/(1-y) - 2))

## use function to move to the (0, 1) set
f(seq(.3, 2, .1))

## show the inverse works
finv(f(seq(.3, 2, .1)))

## Graph the two functions
curve(f, from = -100, to = 100, n = 1000)
curve(finv, from = .001, to = .999, n = 1000)

although this technically puts you into the (0, 1) set rather than [0,
1].  For more information on this general sort of thing, search for
bijection.  By the way, I believe I owe credit for those functions
to one of my math texts at some point, but I cannot remember the
reference (or perhaps my younger self was smarter than I recall (or my
memory has gotten worse than I think...)).

Josh



 HTH,
 Jorge

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.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] CovMMest

2011-08-21 Thread mazlina Abu Bakar
Dear experts,

I'm having problem in using CovMMest (for MM estimates of location and
scale)
I have installed robustbase, robust.
Unfortunately I could not run the command. It says CovMMest is not a
function.
What is wrong? Thx.

-Mag

[[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] CovMMest

2011-08-21 Thread David Winsemius


On Aug 21, 2011, at 9:56 PM, mazlina Abu Bakar wrote:


Dear experts,

I'm having problem in using CovMMest (for MM estimates of location and
scale)
I have installed robustbase, robust.
Unfortunately I could not run the command. It says CovMMest is not a
function.
What is wrong? Thx.



Who can tell? No code. In particular we cannot tell if you ever loaded  
(whatever) package has that function.


--

David Winsemius, MD
Heritage Laboratories
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] Wiki/revision control to management of CRAN package repository

2011-08-21 Thread Etienne Low-Décarie
I propose the following humbly, with little know how as to how to implement, 
and realize it may have been proposed many times.  It is just something I had 
on my mind.

Would it be possible/desirable to have the whole CRAN package repository 
accessible through a public wiki, forge or version control interface (ideally a 
fusion of the wiki and forge approach)?


It appears it would be a first for a software repository.

CRAN package repository is becoming a jungle of R code and may do well with 
currating and editorial effort.  This can not/should not be the task of a 
single person or small group of people.  Using a crowd sourced method by 
implementing a wiki approach to the CRAN package repository would allow for the 
rapid editing, sorting and improvement of this impressive and precious 
resource, while also improving the accessibility, visibility and quality of 
individual packages.  It would also bind the 

For example, such an interface would allow the cleaning up of the repository 
through the use of tagging of packages, using similar approaches to the 
wikipedia project 
(http://en.wikipedia.org/wiki/Wikipedia:Template_messages#Cleanup).

Such a tagging approach could be used within existing vcs, if the repository 
was migrated/mirrored within one of these systems.


Packages could be marked using tags for all following actions prior to 
implementing the action.  Actions could be undertaken directly by package users 
after a delay or discussion.

Packages management/editorial effort:
-Merging/
-Combining packages that have:
-Large overlap in functionality
-Are largely interdependant
-Are only minor extensions of another package
-…
-Split/fork
-Subdividing behemoth packages into smaller packages with more 
specific tasks
-Categorization
-Packages could be sorted by use, improvement of Task View
-Tags, keywords could be added to packages for searching
-Packages could be placed in a hierarchy, not only by true 
dependance and reverse dependance, but also by logical dependance/reverse 
dependance
-ie. which package should probably be used with which 
package, an improvement on the see also help section
-Deletion
-Marking/tagging
-a stub/prototype
-broken
Package improvements
-Improving help files
-Adding functions
-Adding examples
-Requiring, improving or adding references
-References to the theory or approach used...
-A section could include a list of articles making use of the 
package, with package users encourage to enter this information
-This would allow package author recognition and allow a 
package impact factor
-Adding key words for indexing and searching
-Function improvement
-Adding compatibility with other packages/formats (including 
when merging packages)
-Speed improvements
Discussion
-On package improvements, management steps directly attached to the 
package
-Help discussion




These actions would be reversible, possibly with veto power from the author of 
the package.

Links:
http://www.rforge.net/
http://sourceforge.net/
http://channel9.msdn.com/Forums/Coffeehouse/174561-Coding-Wiki
http://code.google.com/p/mcover/
http://www.tigris.org/

This is just an idea I had on my mind.

Thank you

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