Re: [R] Recursive concatenation

2007-09-04 Thread Dimitris Rizopoulos
try this:

paste(rep(LETTERS[1:3], each = 3), 1:3, sep = "")


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Dennis Fisher <[EMAIL PROTECTED]>:

> Colleagues,
>
> I want to create the following array:
>   "A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"
>
> I recall that there is a trick using "c" or "paste" permitting me to
> form all combinations of c("A", "B", "C") and 1:3.  But, I can't
> recall the trick.
>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] match help

2007-09-03 Thread Dimitris Rizopoulos
try this:

x <- c(NA, NA, 1, NA, NA, NA, NA, 2, NA, NA)

na.ind <- is.na(x)
x[na.ind] <- rnorm(sum(na.ind))
x


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting [EMAIL PROTECTED]:

> In my code, I would like to replace entries in t with
> entries from a random normal distribution.
>
> n<-10
>> nl<-round(1.5+rexp(1,rate=2)
> rate=2))
>> nl
> [1] 2
>> r<-1:n
>> s<-sort(sample(r,nl))
>> t<-match(r,s)
>> r
>  [1]  1  2  3  4  5  6  7  8  9 10
>> s
> [1] 3 8
>> t
>  [1] NA NA  1 NA NA NA NA  2 NA NA
>
> t.random<-function(x) {for(i in 1:n) ifelse(x[i]!=NA,   
> x[i]<-rnorm(1), x[i]<-NA}
>
> t.random(t)
>
> t
>  [1] NA NA  1 NA NA NA NA  2 NA NA
>
>
>
> Thank you for your time,
>
>
> Diana Verzi
> Associate Professor of Mathematics
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] substituting elements in vector according tosample(unique(vector))

2007-08-29 Thread Dimitris Rizopoulos
try the following:

v <- c(1, 2, 1, 2, 3, 3, 1)
x <- c(3, 2, 1)

fv <- factor(v, levels = x)
as.vector(unclass(fv))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Arthur Wuster" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, August 28, 2007 4:12 PM
Subject: [R] substituting elements in vector according 
tosample(unique(vector))


>
> Hello!
>
> Assuming I have a vector, such as
>
> v <- c(1,2,1,2,3,3,1)
>
> This vector has three unique elements: 1, 2, and 3.
>
>> unique(v)
> [1] 1 2 3
>
> If I shuffle this vector of unique elements, I get something like 
> this:
>
>> sample(unique(v))
> [1] 3 2 1
>
> In the vector v I started with, I would now like to replace each 
> element in
> unique(v) with the corresponding element (i.e. the element with the 
> same
> index) in sample(unique(v)).
>
> In this case, the result should be something like c(3,2,3,2,1,1,3).
>
> In particular, I would like to do this without a slow for loop.
> I have tried things like sub(), but they don't seem to be 
> appropriate.
> Can anyone provide an elegant solution?
>
> Thank you,
>
> Arthur Wuster
> Theoretical and Computational Biology
> MRC Laboratory of Molecular Biology
> Cambridge, UK
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Splitting strings

2007-08-23 Thread Dimitris Rizopoulos
one way is the following:

data.frame(status = gsub("[0-9]", "", surgery),
time = gsub("[a-z]", "", surgery))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Gary Collins" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, August 23, 2007 10:03 AM
Subject: [R] Splitting strings


> I'm having a Thursday morning mental block, any suggestions on the 
> following
> would be most appreciated...
>
> I have (as an example)
>
> surgery = c("d48",  "d67",  "dnc37",  "a75",  "d10",  "a78",  "d31",
> "d55",  "d1")
>
> before each number part the possibilities are c("a", "d", "dnc"), 
> I'm trying
> to split each element in "surgery" so that I have,
>
> status time
> d48
> d67
> dnc 37
> a75
> d10
> a78
> d31
> d55
> d1
>
> I've tried various strsplit approaches but nothing has done what I 
> need.
>
> thanks in advance
>
> Gary
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] plot in for loop with "i" indexed variables does not work

2007-08-22 Thread Dimitris Rizopoulos
you need something like this:

par(mfrow = c(5, 5))
for (i in 1:10) {
nam <- paste("Var.", i, sep = "")
plot(x = time, y = mat[, nam], xlab = "Time",
ylab = nam)
}

where `mat' is the matrix containing Var.1, Var.2, Var.3, etc.


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, August 22, 2007 10:56 AM
Subject: [R] plot in for loop with "i" indexed variables does not work


> Hi there
>
> Does anyone know, why this is not working?:
>
>
> par(mfrow = c(5, 5))
>
> for (i in 1:10){
> plot(x=time, y=Var.i)
> }
>
> (x-variable is time
> y-variable is Var out of matrix with columns Var.1 Var.2 Var.3 
> etc...)
>
> even
>
> for (i in 1:10){
> plot(x=time, y=paste("Var", i, sep=".")
> }
>
> does not work
>
> Thanks
>
> marc
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] standardized cronbach's alpha?

2007-08-21 Thread Dimitris Rizopoulos
look at: help("cronbach.alpha", package = "ltm")

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Steve Powell" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, August 21, 2007 4:02 PM
Subject: [R] standardized cronbach's alpha?


Hi list members
Any easy way to get standardized cronbach's alpha for a scale, as in 
SPSS?
Thanks

Steve Powell


proMENTE social research
research | evaluation | training & consulting
Kranjčevićeva 35, 71000 Sarajevo
mobile: +387 61 215 997 | office: +387 33 556 865 | fax: +387 33 556 
866


Checked by AVG Free Edition.

17:44

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Select rows of matrix

2007-08-20 Thread Dimitris Rizopoulos
try this:

mat <- matrix(rnorm(20*10), 20, 10)
mat[sample(200, 10)] <- -Inf
mat
mat[apply(is.finite(mat), 1, all), ]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Van Wyk, Jaap" <[EMAIL PROTECTED]>
To: 
Sent: Monday, August 20, 2007 2:36 PM
Subject: [R] Select rows of matrix


> Hi
>
> I would appreciate if anyone could help me with an elegant solution 
> of
> the following:
>
> I have a matrix that contain a small number of -Inf values.
>
> How can form a new matrix from the old one that excludes all the 
> rows
> with -Inf values ?
>
>
>
> Thank you.
>
> Jacob
>
>
>
> Dept of Statistics
>
> University of Johannesburg
>
> South Africa
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] values from a linear model

2007-07-24 Thread Dimitris Rizopoulos
try this:

coef(summary(mod))[, "Std. Error"]


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Manuele Pesenti" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, July 24, 2007 12:02 PM
Subject: [R] values from a linear model


> Dear R users,
> how can I extrapolate values listed in the summary of an lm model 
> but not
> directly available between object values such as the the standard 
> errors of
> the calculated parameters?
>
> for example I got a model:
>
> mod <- lm(Crd ~ 1 + Week, data=data)
>
> and its summary:
>
>> summary(mod)
>
> Call:
> lm(formula = Crd ~ 1 + Week, data = data, model = TRUE, y = TRUE)
>
> Residuals:
>   Min 1Q Median 3QMax
> -4.299e-03 -1.653e-03  2.628e-05  1.291e-03  5.130e-03
>
> Coefficients:
> Estimate Std. Error  t value Pr(>|t|)
> (Intercept) 1.000e+01  3.962e-04 25238.73   <2e-16 ***
> Week5.038e-04  6.812e-0673.96   <2e-16 ***
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Residual standard error: 0.001966 on 98 degrees of freedom
> Multiple R-Squared: 0.9824, Adjusted R-squared: 0.9822
> F-statistic:  5469 on 1 and 98 DF,  p-value: < 2.2e-16
>
> I'm interested in values of Std. Error of coefficients...
>
> thank you very much
>
> Best regards
> Manuele
>
> -- 
> Manuele Pesenti
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> http://mpesenti.polito.it
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] Help on "looping problem" needed!

2007-07-23 Thread Dimitris Rizopoulos
try this:

tol <- 0.01
mat <- matrix(as.numeric(NA), 1000, 5)
k <- 1
while(any(is.na(mat))){
x <- rnorm(1000, sd = 0.02)
if (abs(mean(x)) < tol) {
mat[, k] <- x
k <- k + 1
}
}

abs(colMeans(mat))
par(mfrow = c(2, 3))
apply(mat, 2, hist)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Ing. Michal Kneifl, Ph.D." <[EMAIL PROTECTED]>
To: "Rhelp" 
Sent: Monday, July 23, 2007 4:40 PM
Subject: [R] Help on "looping problem" needed!


>I am wondering if someone could help me out with following problem:
> I have written a for loop which generates a random normal 
> distribution
> let us say 1000 times.
> When the restriction is met (mean<0.01), the loop stops, prints
> the mean value and plots a histogram.
>
> for(i in 1:1000) {
> a<-rnorm(1000,0,.2)
> b<-abs(mean(a))
> if(b>.01) next else {print(b);hist(a);break}}
>
> How to reshape the loop when I want to find at least 5 distibutions
> that meet my restriction and save them (assign) under
> names R1R5.
> Could you help me please?
>
> Michael
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] extraction of vector elements to new list

2007-07-23 Thread Dimitris Rizopoulos
try this:

new.list <- lapply(my.list, "[", i = 1:2)
new.list


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Patrick Zimmermann" <[EMAIL PROTECTED]>
To: 
Sent: Monday, July 23, 2007 3:59 PM
Subject: [R] extraction of vector elements to new list


> Dear R-community,
>
> I have got a list of vectors and would like to extract the first two
> elements of each vector to a new list.
>
> My list is of the style:
>
> my.list = list(c("a", "b", "c"), c("d", "e"), c("f", "g", "h", "i"), 
> ...)
>
> #I want:
>
> new.list = list(c("a", "b"), c("d", "e"), c("f", "g"), ...)
>
> # As
>
> my.list[[3]][1:2]
>
> # is [1] "f" "g"
>
> # I thought
>
> my.list[[1:3]][1:2]
>
> # would be
>
> # [[1]]
> # [1] "a" "b"
>
> # [[2]]
> # [1] "d" "d"
>
> # [[3]]
> # [1] "f" "g"
>
> # but is: 'Error: recursive indexing failed at level 2'
>
>
> I think it should be easy, but none of my tried combinations of '['
> and 'c(' worked.
> Who can help?
>
> Patrick
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] create an array with rep

2007-07-22 Thread Dimitris Rizopoulos
try this:

x <- -3:3
as.matrix(expand.grid(x, x))
# or
t(as.matrix(expand.grid(x, x)))


I hope it helps.

Best,
Dimitris


----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting baptiste Auguié <[EMAIL PROTECTED]>:

>
> Hi,
>
>
> I want to make the following array of numbers:
>
> -3 -3 -3 -3 -3 -3 -3 -2 -2 -2 -2 -2 -2 -2 ...  3  3  3  3  3  3  3
> -3 -2 -1  0  1  2  3 -3 -2 -1  0  1  2  3 ... -3 -2 -1  0  1  2  3
>
> (3 would be N, a painful example to type number).
>
> Here is my dirty attempt to do it,
>
>> N<-3
>>
>> x<-c(-N:N)
>>
>> rj<-rbind(matrix(outer(matrix(1,1,2*N+1),x),nrow=1),rep(x,2*N+1))
>>
>
> It sort of works, but I'd like some advice on how to do it properly
> as I'm very new to R and N may be big at some point.
>
> Thanks,
>
> baptiste
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] GEE code

2007-07-20 Thread Dimitris Rizopoulos
from your description I think you need a random-effects model. Since 
you assume normality the parameter estimates from a random-effects 
model (in your case `GDP.log2') have a marginal interpretation (in 
fact they have both conditional and marginal interpretation). Thus, 
you could also use lmer() from package `lme4' to fit such a model, 
e.g.,

fit1 <- lmer(ineq ~ GDP.log2 + (1 | country), data = data3)
summary(fit1)
# intercept + Emprirical Bayes estimates of
# the random-effect per country
fixef(fit1)[1] + unlist(ranef(fit1))

If you have repeated measurement in time, you could include 
random-slopes (e.g., in lmer()) or an AR1 structure, as you did below. 
For the latter case, you probably want to use functions lme() and 
gls() from package `nlme'.


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Chris Linton" <[EMAIL PROTECTED]>
To: 
Sent: Friday, July 20, 2007 9:34 AM
Subject: [R] GEE code


> I'm writing a paper aimed at motivating the use of GEE within the 
> field of
> economics.  However, after computing using the geeglm function, I 
> noticed
> there's one intercept in the summary output.  I assume this means 
> the
> function is pooling the data.  That means my code is not what I 
> want.  I
> want a "fixed effects" model, meaning I want the intercept to vary 
> by
> cluster.  Here's my current code.
>
> gfit4<-geeglm(ineq~GDP.log2,family=gaussian(link="identity"),data=data3,id=country,corstr="ar1")
> summary(gfit4)
>
>
> What do I need to include to get the function to compute a model 
> where the
> intercept varies by the country?
>
>
>
> Thanks
>
> -chris linton
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] EM unsupervised clustering

2007-07-18 Thread Dimitris Rizopoulos
you could also have a look at function lca() from package `e1071' that 
performs a latent class analysis, e.g.,

fit1 <- lca(data, 2)
fit1

fit2 <- lca(data, 3)
fit2

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Federico Calboli" <[EMAIL PROTECTED]>
To: "r-help" 
Sent: Wednesday, July 18, 2007 3:37 PM
Subject: [R] EM unsupervised clustering


> Hi All,
>
> I have a  n x m matrix. The n rows are individuals, the m columns 
> are variables.
>
> The matrix is in itself a collection of 1s (if a variable is 
> observed for an
> individual), and 0s (is there is no observation).
>
> Something like:
>
>  [,1] [,2] [,3] [,4] [,5] [,6]
> [1,]101100
> [2,]101100
> [3,]101100
> [4,]010000
> [5,]101100
> [6,]010010
>
>
> I use kmeans to find 2 or 3 clusters in this matrix
>
> k2 = kmeans(data, 2, 1000)
> k3 = kmeans(data, 3, 1000)
>
> but I would like to use something a bit more refined, so I though 
> about a EM
> based clustering. I am using the Mclust() function from the mclust 
> package, but
> I get the following (to me incomprehensible) error message:
>
> plot(Mclust(as.data.frame(data)), as.data.frame(data))
> Hit  to see next plot:
> Hit  to see next plot:
> Hit  to see next plot:
> Error in 1:L : NA/NaN argument
> In addition: Warning messages:
> 1: best model occurs at the min or max # of components considered 
> in:
> summary.mclustBIC(Bic, data, G = G, modelNames = modelNames)
> 2: optimal number of clusters occurs at min choice in:
> Mclust(as.data.frame(anc.st.mat))
> 3: insufficient input for specified plot in: coordProj(data = data, 
> parameters =
> x$parameters, z = x$z, what = "classification",
>
> That's puzzling because the example given by ?Mclust is something 
> like
>
> plot(Mclust(iris[,-5]), iris[,-5])
>
> which is pretty simple and dumbproof and works flawlessly...
>
> best,
>
> Federico
>
> -- 
> Federico C. F. Calboli
> Department of Epidemiology and Public Health
> Imperial College, St Mary's Campus
> Norfolk Place, London W2 1PG
>
> Tel  +44 (0)20 7594 1602 Fax (+44) 020 7594 3193
>
> f.calboli [.a.t] imperial.ac.uk
> f.calboli [.a.t] gmail.com
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] multiple rugs on a single plot

2007-07-17 Thread Dimitris Rizopoulos
you could use different colours, e.g.,

x1 <- rnorm(100, -2.5, 1)
x2 <- rnorm(100, 0, 1)
x3 <- rnorm(100, 2.5, 1)
x <- c(x1, x2, x3)

plot(density(x))
rug(x1, col = "red")
rug(x2, col = "black")
rug(x3, col = "blue")

or something like the following:

plot(density(x))
len <- 0.005
ds <- 0.001
segments(x1, -1, x1, 0)
segments(x2, 0 + ds, x2, len)
segments(x3, len + ds, x3, 2*len)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Quin Wills" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, July 17, 2007 12:50 PM
Subject: [R] multiple rugs on a single plot


> Hi
>
>
>
> I could only find some discussion on this wrt lattice graphics 
> (which I'm
> not using). Apologies if I'm missing something obvious.
>
>
>
> I'd like to produce 3 rug plots under a kernel density plot for a
> population. The population is subdivided into 3 subpopulations, 
> which I'd
> like the rug plots to highlight. Naturally, when I do 3 rug plots, 
> they all
> plot over each other. I'd like 3 parallel rug plots along the 
> x-axis. But
> how.
>
>
>
> Thanks in advance,
>
> Quin
>
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] counting occurances of matching rows in a matrix

2007-07-13 Thread Dimitris Rizopoulos
one way is the following (maybe there're better):

pats <- do.call(paste, c(as.data.frame(M), sep = "\r"))
pats <- factor(pats, levels = unique(pats))
cbind(unique(M), Freq = as.vector(table(pats)))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Balazs Torma" <[EMAIL PROTECTED]>
To: 
Sent: Friday, July 13, 2007 4:11 PM
Subject: [R] counting occurances of matching rows in a matrix


>I need help regarding to the following problem:
>
> Consider this matrix:
>
>> M <- matrix(c(1,2, 4,3, 1, 2),3, 2, byrow=TRUE)
>> M
> [,1] [,2]
> [1,]12
> [2,]43
> [3,]12
>
> I would like to have a matrix which counts the identical rows and 
> places the counts into its third column. I tried with ftable():
>
>> as.data.frame(ftable(M[,1], M[,2]))
>  Var1 Var2 Freq
> 1122
> 2420
> 3130
> 4431
>
> This would be exactly what I want without the 0-freq rows. The 
> problem is that ftable() counts the occurances of all possible 
> factor combinations, which is inproper because the real matrix is 
> very long for which I want to count. (I know that I could filter out 
> 0-frequencies afterwards but I would like ftable not to produce 
> 0-frequencies unnecessarily (it would consume too much space)).
>
> I tried table() too, but I couldn't tell it that it should consider 
> each row as one data point, and not all elements in the matrix 
> separately:
>
>> as.data.frame(table(M))
>  M Freq
> 1 12
> 2 22
> 3 31
> 4 41
>
> Any help greatly appreciated!
> Balazs Torma
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] nearest correlation to polychoric

2007-07-13 Thread Dimitris Rizopoulos
you could also have a look at function posdefify() from package 
`sfsmisc'.

I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: ""Jens Oehlschlägel"" <[EMAIL PROTECTED]>
To: 
Sent: Friday, July 13, 2007 2:25 PM
Subject: [R] nearest correlation to polychoric


Dear all,

Has someone implemented in R (or any other language)

Knol DL, ten Berge JMF.  Least-squares approximation of an improper 
correlation matrix by a proper one.  Psychometrika, 1989, 54, 53-61.

or any other similar algorithm?

Best regards


Jens  Oehlschlägel


Background:

I want to factanal() matrices of polychoric correlations which have 
negative eigenvalue. I coded

Highham 2002 Computing the nearest correlation matrix - a problem from 
finance, IMA Journal of Numerical Analysis (2002), 22, 329-343.

which basically works but still leaves very small negative eigenvalues 
which causes factanal() to fail with

> factanal(cov=ncor$cor, factors=2)
Fehler in optim(start, FAfn, FAgr, method = "L-BFGS-B", lower = lower, 
:
L-BFGS-B benötigt endliche Werte von 'fn'
Zusätzlich: Warning message:
NaNs wurden erzeugt in: log(x)
> version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  4.1
year   2006
month  12
day18
svn rev40228
language   R
version.string R version 2.4.1 (2006-12-18)

--

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 get the p-values from an lm function ?

2007-07-12 Thread Dimitris Rizopoulos
try the following:

tmp <- by(projet, rating, function (x) Thursday, 12.July.2007{
fit <- lm(defaults ~ CGDP + CSAVE + SP500, data = x)
summary(fit)$coefficients
})


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Benoit Chemineau" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, July 12, 2007 10:51 AM
Subject: [R] how to get the p-values from an lm function ?


> Hi, dear R-users,
>
> I am computing a liner regression by rating category using the 'by' 
> function
> as stated below:
>
> tmp <- by(projet, rating, function(x) lm(defaults ~ 
> CGDP+CSAVE+SP500, data =
> x))
>
> I would like to get not only the coefficients but also their 
> p-values. I
> can't find the command in the help pages to get them.
>
> Does anyone have a suggestion ?
>
> Thank you,
>
> Benoit.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] compare 2 vectors

2007-06-28 Thread Dimitris Rizopoulos
look at setdiff(), e.g.,

setdiff(b, a)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "João Fadista" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, June 28, 2007 11:55 AM
Subject: [R] compare 2 vectors


Dear all,

I would like to take out the values from one vector that are equal to 
the values in another vector.

Example:
a <- c(1,2,3,4,5,6,7,8,9)
b <- c(3,10,20,5,6)
b_noRepeats = c(10,20)

So I would like to have the vector b without the same values as vector 
a.


Kind regards,
João Fadista





[[alternative HTML version deleted]]







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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] create matrix from comparing two vectors

2007-06-26 Thread Dimitris Rizopoulos
try this:

test <- 1:10
fac <- c(3, 6, 9)

outer(test, fac, "<") * 1


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Van Campenhout Bjorn <[EMAIL PROTECTED]>:

> hi all, sorry for this basic question, I think I know I should use   
> ?apply, but it is really confusing me...
>
> I want to create a matrix by comparing two vectors.  Eg:
>
> test<-seq(1:10)
> fac<-c(3,6,9)
>
> and i want to end up with a 10*3 matrix with a boolean that tests if  
>  test
> 1 1 1
> 1 1 1
> 0 1 1
> 0 1 1
> 0 1 1
> 0 0 1
> 0 0 1
> 0 0 1
> 0 0 0
> 0 0 0
>
> I can't find the solution without using a loop...
>
> B
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 ave this?

2007-06-23 Thread Dimitris Rizopoulos
you could give a try to the following functions:

matFun <- function(lis, FUN){
 if(!is.list(lis) || !all(sapply(lis, is.matrix)))
 stop("'lis' must be a list containing 2-dimensional arrays")
 dims <- sapply(lis, dim)
 n <- dims[1, 1]
 p <- dims[2, 1]
 if(!all(n == dims[1, ]) || !all(p == dims[2, ]))
 stop("the matrices must have the same dimensions")
 mat <- matrix(unlist(lis), n * p, length(lis))
 matrix(apply(mat, 1, FUN), n, p)
}

matSums <- function(lis){
 if(!is.list(lis) || !all(sapply(lis, is.matrix)))
 stop("'lis' must be a list containing 2-dimensional arrays")
 dims <- sapply(lis, dim)
 n <- dims[1, 1]
 p <- dims[2, 1]
 if(!all(n == dims[1, ]) || !all(p == dims[2, ]))
 stop("the matrices must have the same dimensions")
 out <- array(data = 0, dim = c(n, p))
 for(i in seq(along = lis))
 out <- out + lis[[i]]
 out
}



n <- 6
p <- 5
lis <- list(matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p),
matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p),
matrix(rnorm(n * p), n, p))

matFun(lis, sum)
matSums(lis)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Weiwei Shi <[EMAIL PROTECTED]>:

> one of my approaches is:
>
> x0 = sapply(mylist, cbind)
>
> and manipulate from x0 (x0[1:nrow(x0)/2, ] correponds to fc and the
> lower part is tt.
>
> but it is not neat way.
>
>
> On 6/22/07, Weiwei Shi <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I have a list that looks like this:
>> [[1]]
>>  fc  tt
>> 50   0.07526882 0.0
>> 100  0.09289617 0.0
>> 150  0.12359551 0.0
>>
>> [[2]]
>>  fc  tt
>> 50   0.02040816 0.0
>> 100  0.03626943 0.005025126
>> 150  0.05263158 0.010101010
>>
>> and I am wondering how to "average" it so that I have one matrix t0 at
>> the end, and t0[1,1] = (0.075..+0.0204..)/2
>>
>> Thanks,
>>
>> --
>> Weiwei Shi, Ph.D
>> Research Scientist
>> GeneGO, Inc.
>>
>> "Did you always know?"
>> "No, I did not. But I believed..."
>> ---Matrix III
>>
>
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] generating a new variable based on results of a by command

2007-06-21 Thread Dimitris Rizopoulos
maybe you want to use ave(), e.g.,

f$sums <- ave(f$b, f$e, FUN = sum)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Economics Guy" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, June 21, 2007 3:53 PM
Subject: [R] generating a new variable based on results of a by 
command


>I have a matrix with a set of variables one of which is a factor. 
>Using by()
> I have calculated something about each group (say the sum). Now I 
> want to
> create a new variable in the original matrix that contains the 
> results of
> the by() for each observation that is in the corresponding group.
>
> For example I have:
>
> -
>
> a <-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>
> b <-c(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)
>
> e 
> <-c("A","B","C","D","E","F","A","B","C","D","E","F","D","E","F","A")
>
> f <-data.frame(e,a,b)
>
> # Calculate sum by group
>
> sums <- by(f, e, function(x) sum(x$b))
>
> ---
>
> Now I would like to assign each observation in f a new variable 
> based on the
> results of the by(). I converted sums into a matrix and then tried 
> using
> match() and ifthen() but could not get it to work.
>
> Thanks,
>
> EG
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Got "Unexpected ELSE error"

2007-06-20 Thread Dimitris Rizopoulos
the problem is that you start `else' on a new line; check the 
following two solutions:

if ( a ) {
cat("TRUE", "\n")
} else {
cat("FALSE", "\n")
}

# or

{
if ( a )
{
cat("TRUE", "\n")
}
else
{
    cat("FALSE", "\n")
}
}


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Shiazy Fuzzy" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, June 20, 2007 11:41 AM
Subject: [R] Got "Unexpected ELSE error"


> Dear R-users,
>
> I have a problem with the IF-ELSE syntax.
> Please look at the folllowing code and tell me what's wrong:
>
> a <- TRUE
> if ( a )
> {
>cat("TRUE","\n")
> }
> else
> {
>cat("FALSE","\n")
> }
>
> If I try to execute with R I get:
> Error: syntax error, unexpected ELSE in "else"
> The strange thing is either "cat" instructions are executed!!
>
> My system is: Fedora Core 6 x86_64 + R 2.5.0 (rpm)
>
> Thank you very much in advance
>
> Regards,
>
> -- Marco
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Gini coefficient in R

2007-06-11 Thread Dimitris Rizopoulos
try this version instead:

gini <- function(x, unbiased = TRUE, na.rm = FALSE){
if (!is.numeric(x)){
warning("'x' is not numeric; returning NA")
return(NA)
}
if (!na.rm && any(na.ind <- is.na(x)))
stop("'x' contain NAs")
if (na.rm)
x <- x[!na.ind]
n <- length(x)
mu <- mean(x)
N <- if (unbiased) n * (n - 1) else n * n
ox <- x[order(x)]
dsum <- drop(crossprod(2 * 1:n - n - 1,  ox))
dsum / (mu * N)
}

####

gini(c(100,0,0,0))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "MICHELE DE MEO" <[EMAIL PROTECTED]>
To: 
Sent: Monday, June 11, 2007 4:13 PM
Subject: [R] Gini coefficient in R


> If I use the Ineq library and the Gini function in this way:
>
>>Gini(c(100,0,0,0))
>
> I obtain the result 0.75 instead of 1 (that is the perfect 
> inequality).
>
> I think Gini's formula in Ineq is based on a formula as reported 
> here:
> http://mathworld.wolfram.com/GiniCoefficient.html
>
> but in the case of perfect inequality:
>
> x_1=...=x_n-1 =0
>
> x_n>0
>
> these formula are equal to 1 - 1/n, not to 1.
>
> I don't know where I'm wrong
>
>
> -- 
> Michele De Meo
> http://micheledemeo.blogspot.com/
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] find position

2007-06-10 Thread Dimitris Rizopoulos
try this:

which(a == 0.4)[1]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting gallon li <[EMAIL PROTECTED]>:

> find the position of the first value who equals certain number in a vector:
>
> Say a=c(0,0,0,0,0.2, 0.2, 0.4,0.4,0.5)
>
> i wish to return the index value in a for which the value in the vector is
> equal to 0.4 for the first time. in this case, it is 7.
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] logical 'or' on list of vectors

2007-06-08 Thread Dimitris Rizopoulos
try the following:

as.logical(rowSums(is.na(Theoph)))
## or
!complete.cases(Theoph)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Tim Bergsma" <[EMAIL PROTECTED]>
To: 
Sent: Friday, June 08, 2007 2:57 PM
Subject: [R] logical 'or' on list of vectors


> Suppose I have a list of logicals, such as returned by lapply:
>
> Theoph$Dose[1] <- NA
> Theoph$Time[2] <- NA
> Theoph$conc[3] <- NA
> lapply(Theoph,is.na)
>
> Is there a direct way to execute logical "or" across all vectors? 
> The
> following gives the desired result, but seems unnecessarily complex.
>
> as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))
>
> Regards,
>
> Tim
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sorting dataframe by different columns

2007-06-08 Thread Dimitris Rizopoulos
probably the function sort.data.frame() posted in R-help some time ago 
can be useful; check:

RSiteSearch("sort.data.frame")


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Gunther Höning" <[EMAIL PROTECTED]>
To: 
Sent: Friday, June 08, 2007 8:58 AM
Subject: [R] Sorting dataframe by different columns


> Dear list,
>
> I have a very short question,
> Suggest a dataframe of four columns.
>
> df <- data.frame(w,x,y,z)
>
> I want this ordered the following way:
> first by :x, decreasing = FALSE
> and
> secondly by: z, decreasing =TRUE
>
> How can this be done ?
>
> Thanks
>
> Gunther
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Abstract plot

2007-06-04 Thread Dimitris Rizopoulos
maybe you're looking for curve(), e.g.,

curve(5*x + 2, -3, 4, ylab = expression(5*x + 2))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Alberto Monteiro" <[EMAIL PROTECTED]>
To: 
Sent: Monday, June 04, 2007 3:18 PM
Subject: [R] Abstract plot


>I want to make a plot, but instead of showing _numerical_ values,
> I would like to show _symbolic_ values.
>
> For example, I want to plot a function y = a x + b, where
> x varies between Xmin and Xmax. I would like the plot
> to show, in the x-axis, the strings Xmin and Xmax, instead
> of their numeric values. Is it possible?
>
> Alberto Monteiro
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 obtain coefficient standard error from the result ofpolr?

2007-06-04 Thread Dimitris Rizopoulos
You need to call the summary() method to obtain the standard errors, 
e.g.,

result.plr <- polr(formula, data = mydata, method = "probit", Hess = 
TRUE)
coef(summary(result.plr))

for checking which predictors are significant you also use stepAIC() 
or the bootstrap version of it, i.e., boot.stepAIC() in the 
`bootStepAIC' package, e.g.,

library(bootStepAIC)
boot.stepAIC(result.plr, data = mydata)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Monday, June 04, 2007 8:02 AM
Subject: [R] How to obtain coefficient standard error from the result 
ofpolr?


> Hi - I am using polr. I can get a result from polr fit by calling
>
> result.plr <- polr(formula, data=mydata, method="probit");
>
> However, from the 'result.plr', how can I access standard error of 
> the estimated coefficients as well as the t statistics for each one 
> of them?
>
> What I would like to do ultimately is to see which coefficients are 
> not significant and try to refit the model again by excluding those 
> variables out. I would appreciate if anyone could give some hint on 
> this. Thank you.
>
> - adschai
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] tapply

2007-06-01 Thread Dimitris Rizopoulos
try this:

tapply(re, list(reg, ast), function(x) shapiro.test(x)$p.value)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "livia" <[EMAIL PROTECTED]>
To: 
Sent: Friday, June 01, 2007 1:00 PM
Subject: [R] tapply


>
> Hello, I want to conduct normality test to a series of data and get 
> the
> p-value for each subset. I am using the following codes, but it does 
> not
> work.
>
> tapply(re, list(reg, ast), pvalue(shapiro.test))
>
> Could anyone give me some advice? Many thanks.
> -- 
> View this message in context: 
> http://www.nabble.com/tapply-tf3851631.html#a10910748
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 extract the maximum from a matrix?

2007-06-01 Thread Dimitris Rizopoulos
look at the `arr.ind' argument of ?which(), e.g.,

x <- matrix(rnorm(9), 3, 3)
x
which(x == max(x), arr.ind = TRUE)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "mirko sanpietrucci" <[EMAIL PROTECTED]>
To: 
Sent: Friday, June 01, 2007 11:09 AM
Subject: [R] how to extract the maximum from a matrix?


> Dear UseRs,
> I have a very simple question. I have a big matrix (say x) including
> probabilities (values in (0,1)).
> I have to store in a list the names of the row and the column where 
> max(x)
> is located. How can I proceed?
>
> Thanks in advance for your assistance!
>
> mirko
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] about the unscaled covariances from a summary.lm object

2007-05-29 Thread Dimitris Rizopoulos
try the following:

x1 <- rnorm(100)
x2 <- rep(0:1, each = 50)
x3 <- runif(100)
y <- drop(cbind(1, x1, x2, x3) %*% c(1, 2, -1, -3)) + rnorm(100, sd = 
2)
dat <- data.frame(y, x1, x2, x3)

##

fit.lm <- lm(y ~ x1 + x2 + x3, dat)
summ.fit.lm <- summary(fit.lm)
X <- model.matrix(fit.lm)

all.equal(solve(crossprod(X)), summ.fit.lm$cov.unscaled)

Sigma <- summ.fit.lm$sigma^2 * solve(crossprod(X))
all.equal(sqrt(diag(Sigma)), summ.fit.lm$coefficients[, "Std. Error"])


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Martin Ivanov" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, May 29, 2007 3:12 PM
Subject: [R] about the unscaled covariances from a summary.lm object


> Hello!
> I want to clarify something about the unscaled covarinces component 
> of a summary.lm object. So we have the regressor matrix X. If the 
> fitted lm object is lmobj, the inverse of the matrix t(X)%*%X is xx, 
> and the residual variance is sigma^2_e, the variance-covariance 
> matrix of the OLS estimate of the coefficients is given by:
> xx*sigma^2_e
> I saw that what the function vcov actually does is simply:
> vcov=summary(lmobj)$sigma^2 * summary(lmobj)$cov.unscaled
> So the cov.unscaled component should give the matrix xx. I am right?
> I tried inverting the matrix t(X)%*%X with solve by issuing:
> solve(t(X)%*%X), but I get a matrix quite different from the matrix 
> given by cov.unscaled. Is it just computational instability, or I am 
> missing something important?
>
> Regards,
> Martin
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Number of NA's in every second column

2007-05-20 Thread Dimitris Rizopoulos
sorry but I misread the part about every second column of the  
data.frame; in this case you could use:

rowSums(sapply(dfr[seq(1, length(dfr), 2)], is.na))

I hope it helps.

Best,
Dimitris


-- 
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Lauri Nikkinen <[EMAIL PROTECTED]>:

> Hi R-users,
>
> How do I calculate a number of NA's in a row of every second column in my
> data frame?
>
> As a starting point:
> dfr <- data.frame(sapply(x, function(x) sample(0:x, 6, replace = TRUE)))
> dfr[dfr==0] <- NA
>
> So, I would like to count the number of NA in row one, two, three etc. of
> columns X1, X3, X5 etc.
>
> Thanks in advance
> Lauri
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Number of NA's in every second column

2007-05-20 Thread Dimitris Rizopoulos
for data.frames try:

rowSums(sapply(dfr, is.na))

whereas for matrices you could use:

rowSums(is.na(mat))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Lauri Nikkinen <[EMAIL PROTECTED]>:

> Hi R-users,
>
> How do I calculate a number of NA's in a row of every second column in my
> data frame?
>
> As a starting point:
> dfr <- data.frame(sapply(x, function(x) sample(0:x, 6, replace = TRUE)))
> dfr[dfr==0] <- NA
>
> So, I would like to count the number of NA in row one, two, three etc. of
> columns X1, X3, X5 etc.
>
> Thanks in advance
> Lauri
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] lapply not reading arguments from the correct environment

2007-05-18 Thread Dimitris Rizopoulos
subset() was not defined inside myfun(); try this version instead:

myfun <- function () {
foo <- data.frame(1:10, 10:1)
foos <- list(foo)
fooCollumn <- 2
my.subset <- function(...) subset(...)
cFoo <-  lapply(foos, my.subset, select = fooCollumn)
cFoo
}
myfun()


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "jiho" <[EMAIL PROTECTED]>
To: 
Sent: Friday, May 18, 2007 4:41 PM
Subject: [R] lapply not reading arguments from the correct environment


> Hello,
>
> I am facing a problem with lapply which I ''''think''' may be a bug.
> This is the most basic function in which I can reproduce it:
>
> myfun <- function()
> {
> foo = data.frame(1:10,10:1)
> foos = list(foo)
> fooCollumn=2
> cFoo = lapply(foos,subset,select=fooCollumn)
> return(cFoo)
> }
>
> I am building a list of dataframes, in each of which I want to keep
> only column 2 (obviously I would not do it this way in real life but
> that's just to demonstrate the bug).
> If I execute the commands inline it works but if I clean my
> environment, then define the function and then execute:
> > myfun()
> I get this error:
> Error in eval(expr, envir, enclos) : object "fooCollumn" not found
> while fooCollumn is defined, in the function, right before lapply. 
> In
> addition, if I define it outside the function and then execute the
> function:
> > fooCollumn=1
> > myfun()
> it works but uses the value defined in the general environment and
> not the one defined in the function.
> This is with R 2.5.0 on both OS X and Linux (Fedora Core 6)
> What did I do wrong? Is this indeed a bug? An intended behavior?
> Thanks in advance.
>
> JiHO
> ---
> http://jo.irisson.free.fr/
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simple programming question

2007-05-18 Thread Dimitris Rizopoulos
try this:

dfr <- data.frame(id=1:16, categ=rep(LETTERS[1:4], 4),
var3=c(8,7,6,6,5,4,5,4,3,4,3,2,3,2,1,1))
dfr <- dfr[order(dfr$categ), ]

dfr$score <- unlist(tapply(dfr$var3, dfr$categ, function (x) {
sn <- sort(unique(x), decreasing = TRUE)
labs <- c("high", "mid", rep("low", length(sn) - 2))
labs[match(x, sn)]
}))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Lauri Nikkinen" <[EMAIL PROTECTED]>
To: 
Sent: Friday, May 18, 2007 3:15 PM
Subject: [R] Simple programming question


> Hi R-users,
>
> I have a simple question for R heavy users. If I have a data frame 
> like this
>
>
> dfr <- data.frame(id=1:16, categ=rep(LETTERS[1:4], 4),
> var3=c(8,7,6,6,5,4,5,4,3,4,3,2,3,2,1,1))
> dfr <- dfr[order(dfr$categ),]
>
> and I want to score values or points in variable named "var3" 
> following this
> kind of logic:
>
> 1. the highest value of var3 within category (variable named 
> "categ") ->
> "high"
> 2. the second highest value -> "mid"
> 3. lowest value -> "low"
>
> This would be the output of this reasoning:
>
> dfr$score <-
> factor(c("high","mid","low","low","high","mid","mid","low","high","mid","low","low","high","mid","low","low"))
> dfr
>
> The question is how I do this programmatically in R (i.e. if I have 
> 2000
> rows in my dfr)?
>
> I appreciate your help!
>
> Cheers,
> Lauri
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] add info

2007-05-18 Thread Dimitris Rizopoulos
you could use attributes, e.g.,

dat <- data.frame(x = 1:3, y = letters[1:3])
attr(dat, "name") <- "my data.frame"
attr(dat, "author") <- "John Smith"
attr(dat, "date") <- "2007-05-18"

##

dat
attributes(dat)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "XinMeng" <[EMAIL PROTECTED]>
To: 
Sent: Friday, May 18, 2007 9:05 AM
Subject: [R] add info


> hi all:
> If there's a dataframe:
>
> x y
> 1 a
> 2 b
> 3 c
>
> The info of the data such as :
>
> name
> date
> author
>
> The result I want is:
>
> name
> date
> author
> x y
> 1 a
> 2 b
> 3 c
>
> In other words,I wanna add the info above the dataframe.
>
> How can I do it ?
>
> Thanks a lot!
>
>
> My best
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] more woes trying to convert a data.frame to a numerical matrix

2007-05-16 Thread Dimitris Rizopoulos
have a look at: ?as.numeric() and ?data.matrix().


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Andrew Yee" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, May 16, 2007 2:10 PM
Subject: [R] more woes trying to convert a data.frame to a numerical 
matrix


>I have the following csv file:
>
> name,x,y,z
> category,delta,gamma,epsilon
> a,1,2,3
> b,4,5,6
> c,7,8,9
>
> I'd like to create a numeric matrix of just the numbers in this csv 
> dataset.
>
> I've tried the following program:
>
> sample.data <- read.csv("sample.csv")
> numerical.data <- as.matrix(sample.data[-1,-1])
>
> However, print(numerical.data) returns what appears to be a matrix 
> of
> characters:
>
>  x   y   z
> 2 "1" "2" "3"
> 3 "4" "5" "6"
> 4 "7" "8" "9"
>
> How do I force it to be numbers rather than characters?
>
> Thanks,
> Andrew
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Efficient computation of trimmed stats?

2007-05-15 Thread Dimitris Rizopoulos
the following seems a bit better:

set.seed(1)
nc <- 30
nr <- 25000
x <- matrix(rnorm(nc*nr), ncol = nc)
g <- matrix(sample(1:3, nr*nc, rep = TRUE), ncol = nc)

#

trimmedMeanByGroup1 <- function(y, grp, trim=.05)
   tapply(y, factor(grp, levels=1:3), mean, trim=trim)

trimmedMeanByGroup2 <- function(y, grp, trim = .05){
   unlist(lapply(split(y, grp), mean, trim = trim))
}

out1 <- out2 <- matrix(0, nr, 3)
system.time(for(i in 1:nr) out1[i, ] <- trimmedMeanByGroup1(x[i, ], 
g[i, ]))
system.time(for(i in 1:nr) out2[i, ] <- trimmedMeanByGroup2(x[i, ], 
g[i, ]))

all.equal(out1, out2)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm

- Original Message - 
From: "Benilton Carvalho" <[EMAIL PROTECTED]>
To: "[EMAIL PROTECTED] server posting" 

Sent: Monday, May 14, 2007 6:58 PM
Subject: [R] Efficient computation of trimmed stats?


> Hi everyone,
>
> I was wondering if there is anything already implemented for
> efficient ("row-wise") computation of group-specific trimmed stats
> (mean and sd on the trimmed vector) on large matrices.
>
> For example:
>
> set.seed(1)
> nc = 300
> nr = 25
> x = matrix(rnorm(nc*nr), ncol=nc)
> g = matrix(sample(1:3, nr*nc, rep=T), ncol=nc)
>
> trimmedMeanByGroup <- function(y, grp, trim=.05)
>   tapply(y, factor(grp, levels=1:3), mean, trim=trim)
>
> sapply(1:10, function(i) trimmedMeanByGroup(x[i,], g[i,]))
>
> works fine... but:
>
> > system.time(sapply(1:nr, function(i) trimmedMeanByGroup(x[i,], g
> [i,])))
>user  system elapsed
> 399.928   0.019 399.988
>
> does not look interesting for me.
>
> Maybe some package has some implementation of the above?
>
> Thank you very much,
> -b
>
> --
> Benilton Carvalho
> PhD Candidate
> Department of Biostatistics
> Bloomberg School of Public Health
> Johns Hopkins University
> [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Create an AR(1) covariance matrix

2007-05-11 Thread Dimitris Rizopoulos
one option is the following:

times <- 1:5
rho <- 0.5
sigma <- 2
###
H <- abs(outer(times, times, "-"))
V <- sigma * rho^H
p <- nrow(V)
V[cbind(1:p, 1:p)] <- V[cbind(1:p, 1:p)] * sigma
V


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Rick DeShon" <[EMAIL PROTECTED]>
To: 
Sent: Friday, May 11, 2007 4:29 PM
Subject: [R] Create an AR(1) covariance matrix


> Hi All.
>
> I need to create a first-order autoregressive covariance matrix
> (AR(1)) for a longitudinal mixed-model simulation.  I can do this
> using nested "for" loops but I'm trying to improve my R coding
> proficiency and am curious how it might be done in a more elegant
> manner.
>
> To be clear, if there are 5 time points then the AR(1) matrix is 5x5
> where the diagonal is a constant variance (sigma^2) and the
> covariances depend on the number of "steps" between trials.  So, the
> first off-diagonal of the matrix is sigma*rho, the second 
> off-diagonal
> is sigma*rho^2, the third off-diagonal is sigma*rho^3, and so forth.
>
> Any suggestions for an elegant method to flexibly create this 
> matrix?
>
> Rick DeShon
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] pvmnorm, error message

2007-05-09 Thread Dimitris Rizopoulos
A is not correlation matrix; try this instead:

A <- diag(rep(0.5, 3))
A[1, 2] <- 0.5
A[1, 3] <- 0.25
A[2, 3] <- 0.5
A <- A + t(A)
pmvnorm(lower = rep(-Inf, 3), upper = rep(2, 3), corr = A)


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Andreas Faller" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, May 09, 2007 3:16 PM
Subject: [R] pvmnorm, error message


Hello there!

My operating system is Windows XP, my version of R is the latest 
(R-2.5.0). Recently I have downloaded the package "mvtnorm" and a 
problem with the command "pmvnorm" occured. Trying to enter the lines 
...

A <- diag(3)
A[1,2] <-0.5
A[1,3] <- 0.25
A[2,3] <- 0.5
pvmnorm(lower=c(-Inf,-Inf,-Inf), upper=c(2,2,2),mean = c(0,0,0), 
corr=A)

I got the following error message:

.Fortran("mvtdst", N = as.integer(n), NU=as.integer(df), lower = 
as.double(lower), :
Fortran Symbolname "mvtdst" nicht in der DLL für Paket "mvtnorm"

Can anyone advise what to do now to get rid of this problem? Thank you 
very much indeed.

Regards, Andreas Faller

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] minimum from matrix

2007-05-08 Thread Dimitris Rizopoulos
try this:

apply(a, 2, function(x) min(x[x > 0]))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, May 08, 2007 10:50 AM
Subject: [R] minimum from matrix


>
>
> I have a very large matrix with columns that have some of their
> entries as zero
>
>
> A small example if a=
>
> [,1]  [,2]  [,3]  [,4]
> [,1] 0 2 0 0
> [,2] 1 3 0 3
> [,3] 2 0 3 5
> [,4] 0 4 0 0
>
> and what to get the minimum number from each column but that number
> should not be zero. If I use apply (a,2,min) I will get a vector of
> zeros as the minimum but what I want it for example from column 1 I
> should get 1 i.e for all the matrix I should get a vector (1,2,3,3). 
> I
> wonder if someone can give an idea on how to go about it.
>
> thanks in advance for your help.
>
> Oarabile
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


[R] [R-pkgs] package ltm -- version 0.8-0

2007-05-08 Thread Dimitris Rizopoulos
Dear R-users,

I'd like to announce the release of the new version of package `ltm' 
(i.e., ltm_0.8-0 soon available from CRAN) for Item Response Theory 
analyses. This package provides a flexible framework for analyzing 
dichotomous and polytomous data under IRT, including the Rasch model, 
the Two-Parameter Logistic model, Birnbaum's Three-Parameter model, 
the Latent Trait model with up to two latent variables (allowing also 
for nonlinear terms), and Samejima's Graded Response model. 
Furthermore, supporting functions for descriptive statistics, 
goodness-of-fit, ability estimation and plotting are available.

New features include:

  * The new functions person.fit() and item.fit() compute p-values for 
person- and item-fit statistics for IRT models for dichotomous data. 
The `simulate.p.value' argument enables the computation of p-values 
based on a Monte Carlo procedure.

  * The new function unidimTest() checks the unidimensionality 
assumption for dichotomous data IRT models, using a Modified Parallel 
Analysis.

  * The new function testEquatingData() prepares data-sets for test 
equating by common items. In particular, two types of common item 
equating are included: alternate form equating (where common and 
unique items are analyzed simultaneously) and across sample equating 
(where different sets of unique items are analyzed separately based on 
previously calibrated anchor items).

  * grm() now works with the available cases when incomplete data 
(i.e., in the presence of NAs) are analyzed.

  * better algorithms, for Missing At Random missing data mechanisms, 
have been written for grm(), ltm(), rasch() and tpm().

  * a residuals() method has been added for `grm', `ltm', `rasch', and 
`tpm' objects that computes Pearson-type residuals.

  * factor.scores() and fitted() methods for classes `grm', `ltm', 
`rasch', and `tpm' allow now for NAs in the `resp.patterns' argument, 
enabling thus the computation of ability estimates and fitted values 
for incomplete response patterns.

  * the fitted() method now allows also for the computation of 
marginal and conditional (on the latent variable(s)) probabilities; 
this feature is controlled by the new `type' argument.

  * for more details and other news, check the CHANGES file that ships 
with the package.

More information as well as .R files illustrating the capabilities of 
the package can be found in the Rwiki page of `ltm' available at: 
http://wiki.r-project.org/rwiki/doku.php?id=packages:cran:ltm.

Future plans include the development of functions for fitting Bock's 
Nominal Response model and the option for Differential Item 
Functioning.

I'd like also to thank all users of `ltm' for providing valuable 
feedback, and welcome any additional feedback (questions, suggestions, 
bug-reports, etc.).

Best,
Dimitris


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] intersect of 2 data frames

2007-05-06 Thread Dimitris Rizopoulos
look at ?merge(), e.g., try something like the following:

merge(pretestm, posttest, by = "StuNum")

check also the on-line help page for more info, especially for the  
'all' argument.


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Salvatore Enrico Indiogine <[EMAIL PROTECTED]>:

> Greetings!
>
> I am a new user of R.  The only one in my department, all others use SPSS.
>
> I have two data sets of students with test scores, pretest and
> posttest.  The first column StuNum and then columns of scores.
>
> The problem is that the lists are slightly different not all students
> are in both data sets.
>
> So I did:
>
> intersect(pretest$StuNum, posttest$StuNum) -> common.id
>
> At this point I need to select from pretest the students in common.id
> and do the same with posttest.
>
> I have tried several things but, basically I do not know how to do so.
>
> In SQL it should be something like:
>
> select pretest$StuNum in common.id
>
>
> Any pointers?
>
> Thanks,
> Enrico
>
>
> --
> Enrico Indiogine
>
> Mathematics Education
> Texas A&M University
> [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] logical or for two vectors or matrices

2007-05-04 Thread Dimitris Rizopoulos
you need:

a | b

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Federico Abascal" <[EMAIL PROTECTED]>
To: "R" 
Sent: Friday, May 04, 2007 1:45 PM
Subject: [R] logical or for two vectors or matrices


> Hello,
>
> it might be a very simple question but I cannot find the solution (I 
> tried a || b, any(a,b)... but none works). My problem is:
>
> I have two vectors,
> a <- c(TRUE,FALSE,FALSE)
> b <- c(TRUE,FALSE,TRUE)
>
> and I would like to obtain a vector that indicates if it is TRUE in 
> any of the two vectors. Hence, the desired output would be: TRUE, 
> FALSE, TRUE
>
> Thank you in advance,
> Federico
>
>
> __
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Get the difference between two matrices with different length

2007-05-04 Thread Dimitris Rizopoulos
try this:

ind1 <- do.call("paste", c(as.data.frame(mat1[, 1:2]), sep = "\r"))
ind2 <- do.call("paste", c(as.data.frame(mat2[, 1:2]), sep = "\r"))
mat1[ind1 %in% ind2, 3] - mat2[ind2 %in% ind1, 3]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Felix Wave" <[EMAIL PROTECTED]>
To: 
Sent: Friday, May 04, 2007 1:26 PM
Subject: [R] Get the difference between two matrices with different 
length


> Hello,
> I have got two matrices with different length. The matrices have 3
> columuns. The first two are coordinates. The third is a measurement.
>
> Now I want to get a subtraction between every single value of the
> third column (between matrix1 and matrix2), but only if the two
> first coordinates in matrix1 and matrix2 are the same.
>
> I tried "FUN=?" in aggregate and ave, but I don't know the command
> for such a subtraction?
>
>
> Thank's a lot.
> Felix
>
>
> ---
>
> The matrixes (examlple):
>
> 1 0.1 0.0042
> 1 0.2 0.00423
> 1 0.4 0.00467
> 1 0.5 0.00518
> 1 0.6 0.0061
>
>
> 1 0.1 0.0043
> 1 0.2 0.00442
> 1 0.3 0.00433
> 1 0.4 0.0045
> 1 0.5 0.00524
> 1 0.7 0.006
>
>
>
> My aim:
> ---
> 1 0.1 -0.0001
> 1 0.2 -0.00019
> 1 0.4 0.00017
> 1 0.5 -0.6
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] searching for special variables

2007-05-03 Thread Dimitris Rizopoulos
one option is use something like the following:

a <- 1:10
b777 <- rnorm(10)
c777 <- letters[1:6]
fit <- lm(b777 ~ a)
a777d777 <- 5
##
lis <- ls()
rm(list = c(lis[grep("777", lis)], "lis"))
ls()


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Schmitt, Corinna" <[EMAIL PROTECTED]>
To: 
Cc: "Schmitt, Corinna" <[EMAIL PROTECTED]>
Sent: Thursday, May 03, 2007 9:58 AM
Subject: [R] searching for special variables


> Dear R-Experts,
>
> in my program I have a big workspace. Now I want to look for all
> variables which have the letters "777" in their name (e.g. 
> ask777first)
> and afterwards I need to delete those variables. How can I reach 
> this
> aim?
>
> Any ideas, Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] reference in article

2007-05-02 Thread Dimitris Rizopoulos
try

citation()


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Tomas Mikoviny" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, May 02, 2007 5:44 PM
Subject: [R] reference in article


> Hi all R positive,
>
> does anyone know how to refer R  in article?
>
> thanks
>
> tomas
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] simulation

2007-05-01 Thread Dimitris Rizopoulos
maybe you're looking for something like this:

x <- rpois(999, 2000)
y <- numeric(length(x))
for (i in seq_along(x))
 y[i] <- sum(exp(rgamma(x[i], scale = 2, shape = 0.5)))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Thür Brigitte <[EMAIL PROTECTED]>:

>
> Hello
>
> I would like to simulate datasets in the following way:
>
> x <- rpois(999, 2000)
> y <- sum(exp(rgamma(x, scale=2, shape=0.5)))
>
> The problem is, that by calling "y" I just get 1 value back and not   
> 999 values. Can anyone help me? Thanks!
>
> Brigitte
>
>
>
>
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 a column to a matrix

2007-04-26 Thread Dimitris Rizopoulos
just try:

cbind(m, m[, "censti"] > m[, "survtime"])


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "raymond chiruka" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, April 26, 2007 11:31 AM
Subject: [R] adding a column to a matrix


>i would like to add a variable to an existing matrix by manipulating 
>2 previous variables eg for the data
>  m
> treat strata  censti survTime
>[1,] 1  2  284.684074  690.4961005
>[2,] 1  1  172.764515   32.3990335
>[3,] 1  1 2393.195400   24.6145279
>[4,] 2  1   30.3647718.0272267
>[5,] 1  1  523.182282  554.7659501
>
>  l would want to add a new column censoring by comparing ( if censti 
>  > survtime then censoring=1) how do l go about it
>  thanks
>
>  the code l used to generate the data is
>   n=100
>  > m=matrix(nrow=n,ncol=4)
>  > colnames(m)=c("treat",  "strata", "censti", "survTime")
>  > for(i in 1:100) 
> m[i,]=c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.002),rexp(1,.005))
>  > m
>
>  l know its ugly but it seems to work
>  any suggestions l still new at this
>  thanks
>
>
>
>
> -
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] intersect more than two sets

2007-04-24 Thread Dimitris Rizopoulos
you could try something like the following:

t2 <- lapply(1:11, function(i) c("a", sample(letters[1:5],
sample(10, 1), TRUE), "b"))

unq.vals <- unique(unlist(t2))
ind <- rowSums(sapply(t2, "%in%", x = unq.vals)) == length(t2)
unq.vals[ind]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Weiwei Shi <[EMAIL PROTECTED]>:

> assume t2 is a list of size 11 and each element is a vector of characters.
>
> the following codes can get what I wanted but I assume there might be
> a one-line code for that:
>
> t3 <- t2[[1]]
> for ( i in 2:11){
>   t3 <- intersect(t2[[i]], t3)
> }
>
> or there is no such "apply"?
>
> On 4/24/07, Weiwei Shi <[EMAIL PROTECTED]> wrote:
>> Hi,
>> I searched the archives and did not find a good solution to that.
>>
>> assume I have 10 sets and I want to have the common character   
>> elements of them.
>>
>> how could i do that?
>>
>> --
>> Weiwei Shi, Ph.D
>> Research Scientist
>> GeneGO, Inc.
>>
>> "Did you always know?"
>> "No, I did not. But I believed..."
>> ---Matrix III
>>
>
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] problem in tapply command

2007-04-24 Thread Dimitris Rizopoulos
probably you're looking for

tapply(slp_jeo2$slp, slp_jeo2$jeo, mean, na.rm = TRUE)


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "temiz" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, April 24, 2007 7:21 PM
Subject: [R] problem in tapply command


> hello
>
> when I entered following command, I got NA values for some 
> catagories.
>
> > tapply(slp_jeo2$slp,slp_jeo2$jeo,mean )
>  999   Ca  Cka  DCy   Jh  JKi 
> Kk
> 14.06665   NA 14.60445   NA   NA   NA   NA 
> NA
> KTa KTac   Ku  Kua  Kus   Ky  Kyk 
> ODe
>  NA   NA   NA   NA   NA   NA   NA 
> 17.87489
>PTRc   Qa   TcTkisd
>  NA   NA   NA 19.64067
>
>
> how can I correct this problem ?
>
> regards
>
> -- 
> Ahmet Temiz
>
>
> -- 
> This message has been scanned for viruses and\ dangerous 
> con...{{dropped}}
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] data recoding problem

2007-04-23 Thread Dimitris Rizopoulos
one option is the following:

do.call(rbind, lapply(split(tox, tox$id), function (x) {
if (any(ind <- x$event == 1))
x[which(ind)[1], ]
else
x[nrow(x), ]
}))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Williams Scott" <[EMAIL PROTECTED]>
To: 
Sent: Monday, April 23, 2007 10:14 AM
Subject: [R] data recoding problem


> Hi R experts,
>
> I have a data recoding problem I cant get my head around - I am not 
> that
> great at the subsetting syntax. I have a dataset of longitudinal
> toxicity data (for multistate modelling) for which I want to also 
> want
> to do a simple Kaplan-Meier curve of the time to first toxic event.
>
> The data for 2 cases presently looks like this (one with an event, 
> the
> other without), with id representing each person on study, and 
> follow-up
> time and status:
>
>
>> tox
>
> id  t   event
>
> PMC011  0.000 0
> PMC011  3.154 0
> PMC011  5.914 0
> PMC011 12.353 0
> PMC011 18.103 1
> PMC011 24.312 0
> PMC011 30.029 0
> PMC011 47.967 0
> PMC011 96.953 0
> PMC016  0.000 0
> PMC016  3.943 0
> PMC016  5.782 0
> PMC016 11.762 0
> PMC016 17.741 0
> PMC016 23.951 0
> PMC016 28.353 0
> PMC016 44.747 0
> PMC016 89.692 0
>
> So what I need is an output in the same column format, containing 
> each
> of the unique values of id:
>
> PMC011 18.103 1
> PMC016 89.692 0
>
> In my head, I would do this by looking at each unique value of id 
> (each
> unique case), look down the event data of each of these cases - if 
> there
> is no event (event==0), then I would go to the time column (t) and 
> find
> the max value and paste this time along with a 0 for event. If there
> were an event, I would then need to find the minimum time associated
> with an event to paste across with the event marker. I am sure 
> someone
> out there can point me in the right direction to do this without 
> tedious
> and slow loops. Any help greatly appreciated.
>
> Cheers
>
> Scott
> _
>
> Dr. Scott Williams
>
> MBBS BScMed FRANZCR
>
> Radiation Oncologist
>
> Peter MacCallum Cancer Centre
>
> Melbourne, Australia
>
> ph +61 3 9656 
>
> fax +61 3 9656 1424
>
> [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] hello

2007-04-19 Thread Dimitris Rizopoulos
look at R FAQ 7.10

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "elyakhlifi mustapha" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, April 19, 2007 3:29 PM
Subject: [R] hello


> ok how can I do to cancel le function factor for the moment ican't 
> do this and I'm stuck with my problem for exemple
>
> Id_Rep Id_Geno Val_O Id_TrT1
> 1   1   64238   145   2
> 2   1   64238 1   1
> 3   1   64238 2   1
> 4   1   64238 1   1
> 5   1   64238 1   1
> 6   1   64238 2   1
> 7   1   64238 1   1
> 8   2   64238 1   1
> 9   2   64238 2   1
> 10  2   64238 1   1
> 11  2   64238 1   1
> 12  2   64238 1   1
> 13  2   64238 1   1
> 14  1   64239   144   2
> 15  1   64239 1   1
>
>  but when I write like below I have still levels and I'd like to 
> disappear levels
>
>
>   don[1:15,]$Val_O
> [1] 145 1   2   1   1   2   1   1   2   1   1   1   1   144 1
> 127 Levels: 1 10 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11 
> 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 12 12.1 12.2 12.3 12.4 
> 12.5 12.6 12.7 ... 9.9
>
>
>
> -
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] Problems in programming a simple likelihood

2007-04-19 Thread Dimitris Rizopoulos
try the following:

mlogl <- function (mu, y, X) {
zeta <- as.vector(X %*% mu)
y.logic <- as.logical(y)
lgLik <- numeric(length(y))
lgLik[y.logic] <- pnorm(zeta[y.logic], log.p = TRUE)
lgLik[!y.logic] <- pnorm(zeta[!y.logic], lower.tail = FALSE, log.p 
= TRUE)
-sum(lgLik)
}

women <- 
read.table("http://wps.aw.com/wps/media/objects/2228/2281678/Data_Sets/ASCII/Women13.txt";,
 
header=TRUE)

mu.start <- c(0, -1.5, 0.01)
out <- optim(mu.start, mlogl, method = "BFGS", y = women$J, X = 
cbind(1, women$M, women$S))
out

glm.fit(x = cbind(1, women$M, women$S), y = women$J, family = 
binomial(link = "probit"))$coefficients


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Deepankar Basu" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, April 19, 2007 12:38 AM
Subject: [R] Problems in programming a simple likelihood


> As part of carrying out a complicated maximum likelihood estimation, 
> I
> am trying to learn to program likelihoods in R. I started with a 
> simple
> probit model but am unable to get the code to work. Any help or
> suggestions are most welcome. I give my code below:
>
> 
> mlogl <- function(mu, y, X) {
> n <- nrow(X)
> zeta <- X%*%mu
> llik <- 0
> for (i in 1:n) {
>  if (y[i]==1)
>   llik <- llik + log(pnorm(zeta[i,], mean=0, sd=1))
>  else
>   llik <- llik + log(1-pnorm(zeta[i,], mean=0, sd=1))
>}
> return(-llik)
> }
>
> women <- read.table("~/R/Examples/Women13.txt", header=TRUE)  # DATA
>
> # THE DATA SET CAN BE ACCESSED HERE
> # women <-
> read.table("http://wps.aw.com/wps/media/objects/2228/2281678/Data_Sets/ASCII/Women13.txt";,
>  
> header=TRUE)
> # I HAVE CHANGED THE NAMES OF THE VARIABLES
> # J is changed to "work"
> # M is changed to "mar"
> # S is changed to "school"
>
> attach(women)
>
> # THE VARIABLES OF USE ARE
> #   work: binary dependent variable
> #   mar: whether married or not
> #   school: years of schooling
>
> mu.start <- c(3, -1.5, 10)
> data <- cbind(1, mar, school)
> out <- nlm(mlogl, mu.start, y=work, X=data)
> cat("Results", "\n")
> out$estimate
>
> detach(women)
>
> *
>
> When I try to run the code, this is what I get:
>
>> source("probit.R")
> Results
> Warning messages:
> 1: NA/Inf replaced by maximum positive value
> 2: NA/Inf replaced by maximum positive value
> 3: NA/Inf replaced by maximum positive value
> 4: NA/Inf replaced by maximum positive value
>
> Thanks in advance.
> Deepankar
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 axis lable text size in plots?

2007-04-18 Thread Dimitris Rizopoulos
take a look at ?par() and especially at the 'cex.lab', 'cex.main', and 
'cex.axis' arguments. For instance, you could use something like:

plot(
dafExpo$grn07,dafExpo$grn09,
xlim=c(0,numAxeMax),
ylim=c(0,numAxeMax),
pch=1,
xlab="Green at 7 AM : NOx [(µg/m3)*hour]",
ylab="Green at 9 AM : NOx [(µg/m3)*hour]",
cex.main = 1.8, cex.lab = 1.5, cex.axis = 1.2
)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Martin Hvidberg" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, April 18, 2007 3:26 PM
Subject: [R] Changing axis lable text size in plots?


Dear list

I'm plotting ( boxplot() and plot() ) some data for a publication.
The editor would like the text labels on the plots in a larger font.

I'm doing something like this:



jpeg(
filename = "D:/Martin/Work/CleanPath/RAF1%03d.jpg",
width = 1000,
height = 600,
pointsize = 12,
quality = 100,
bg = "white",
res = 96,
restoreConsole = TRUE
)

boxplot(
dafExpo[,c(1,2,3,4,5,6,7,8,9,10,11,12)],
main = "Total NOx Exposure per trip"
)

numAxeMax = max(dafExpo$grn07, dafExpo$grn09, dafExpo$grn14, 
dafExpo$grn16)

plot(
dafExpo$grn07,dafExpo$grn09,
xlim=c(0,numAxeMax),
ylim=c(0,numAxeMax),
pch=1,
xlab="Green at 7 AM : NOx [(µg/m3)*hour]",
ylab="Green at 9 AM : NOx [(µg/m3)*hour]"
)
abline(0,1)



dafExpo is a dataframe and the above code works just fine.

My question:

How do I change the size of the text seen on the plot, the axis labels
in particular?

My mailbox is spam-free with ChoiceMail, the leader in personal and 
corporate anti-spam solutions. Download your free copy of ChoiceMail 
from www.digiportal.com

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] Two sample t.test, order of comparions

2007-04-18 Thread Dimitris Rizopoulos
take a look at

?relevel()


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Helmut Schütz" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, April 18, 2007 2:46 PM
Subject: [R] Two sample t.test, order of comparions


Dear group members,

I want to compare response variables ("logAUC") of two groups 
(treatment
"Test", "Reference") of a subset ("period == 1") in dataframe "resp"
(below):

   sequence subject period treatment  AUC   logAUC
1RT   1  1 Reference 44.1 3.786460
2RT   1  2  Test 39.1 3.666122
3RT   2  1 Reference 33.6 3.514526
4RT   2  2  Test 23.8 3.169686
5RT   3  1 Reference 45.5 3.817712
6RT   3  2  Test 40.8 3.708682
7TR   4  1  Test 19.5 2.970414
8TR   4  2 Reference 21.1 3.049273
9TR   5  1  Test 67.2 4.207673
10   TR   5  2 Reference 51.5 3.941582
11   TR   6  1  Test 25.7 3.246491
12   TR   6  2 Reference 30.1 3.404525
13   RT   7  1 Reference 35.3 3.563883
14   RT   7  2  Test 26.7 3.284664
15   RT   8  1 Reference 26.0 3.258097
16   RT   8  2  Test 36.5 3.597312
17   RT   9  1 Reference 38.2 3.642836
18   RT   9  2  Test 57.8 4.056989
19   TR  10  1  Test 33.6 3.514526
20   TR  10  2 Reference 32.5 3.481240
21   TR  11  1  Test 25.1 3.222868
22   TR  11  2 Reference 36.8 3.605498
23   TR  12  1  Test 44.1 3.786460
24   TR  12  2 Reference 42.9 3.758872
25   RT  13  1 Reference 25.6 3.242592
26   RT  13  2  Test 20.1 3.000720
27   RT  14  1 Reference 58.0 4.060443
28   RT  14  2  Test 45.3 3.813307
29   RT  15  1 Reference 47.2 3.854394
30   RT  15  2  Test 51.8 3.947390
31   TR  16  1  Test 16.5 2.803360
32   TR  16  2 Reference 21.4 3.063391
33   TR  17  1  Test 47.3 3.856510
34   TR  17  2 Reference 39.4 3.673766
35   TR  18  1  Test 22.6 3.117950
36   TR  18  2 Reference 17.3 2.850707
37   RT  19  1 Reference 17.5 2.862201
38   RT  19  2  Test 30.1 3.404525
39   RT  20  1 Reference 51.7 3.945458
40   RT  20  2  Test 36.0 3.583519
41   RT  21  1 Reference 24.5 3.198673
42   RT  21  2  Test 18.2 2.901422
43   TR  22  1  Test 36.3 3.591818
44   TR  22  2 Reference 27.2 3.303217
45   TR  23  1  Test 29.4 3.380995
46   TR  23  2 Reference 39.6 3.678829
47   TR  24  1  Test 18.3 2.906901
48   TR  24  2 Reference 20.7 3.030134

The formula method of t.test

 > result <- t.test(logAUC ~ treatment, data = resp, subset = (period 
==
1), var.equal = FALSE, conf.level = 0.90)
 > result

gives

Welch Two Sample t-test

data:  logAUC by treatment
t = 1.1123, df = 21.431, p-value = 0.2783
alternative hypothesis: true difference in means is not equal to 0
90 percent confidence interval:
 -0.0973465  0.4542311
sample estimates:
mean in group Reference  mean in group Test
   3.5622733.383831

Now I'm interested rather in the confidence interval of "Test" -
"Reference" rather than "Reference" - "Test" which is given by t.test

Do you know a more elegant way than the clumsy one I have tried?

 > as.numeric(exp(result$estimate[2]-result$estimate[1]))
 > as.numeric(exp(-result$conf.int[2]))
 > as.numeric(exp(-result$conf.int[1]))

Best regards,
Helmut

-- 
Ing. Helmut Schütz
BEBAC - Consultancy Services for
Bioequivalence and Bioavailability Studies
Neubaugasse 36/11
1070 Vienna, Austria
tel/fax +43 1 2311746
e-mail  [EMAIL PROTECTED]
web http://bebac.at
forum   http://forum.bebac.at

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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] Matrix manipulation

2007-04-16 Thread Dimitris Rizopoulos
It would be helpful if you could be more specific of what exactly 
you'd like to compute. Have a look also at the posting guide available 
at:

http://www.R-project.org/posting-guide.html


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Markku Karhunen" <[EMAIL PROTECTED]>
To: 
Sent: Monday, April 16, 2007 2:52 PM
Subject: [R] Matrix manipulation


> Hi,
>
> This is a very basic question, but apparently I am too stupid for 
> it.
>
> I have a large matrix A, and I need to avoid for loops. How could I
> apply a function f(a,r,c) on each element of A, using the subscript 
> (row
> and column) of a as the other arguments?
>
> Thanks in advance,
> Markku Karhunen
> National Public Health Institute,
> Finland
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Assignment from list

2007-04-12 Thread Dimitris Rizopoulos
try the following:

z <- matrix(1, ncol = 249, nrow = 240)
zz <- matrix(1, ncol = 249, nrow = 240)
for (k in seq_along(x)) {
z[rbind(x[[k]])] <- 0
}
zz[xx] <- 0

all.equal(z, zz)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Eric Blanc" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 12, 2007 10:36 AM
Subject: [R] Assignment from list


>I have a list of groups of xy positions I want to set to 0 in an
> array full of 1s. When the assignments are done directly from the
> list, they are incorrect, while if I use a temporary array derived
> from the list the assignments are correct. The following example 
> will
> hopefully make my problem clearer.
>
> The matrices z and zz are initialised with 1. The z and zz values at
> coordinates in list x are then set to 0 using two different methods.
> Although either method should lead to the same results, z and zz are
> different. z is incorrect, because some values in its first row have
> been incorrectly set to 0.
>
> x  <- list( matrix( c( 9, 9, 74, 75 ), nrow=2 ),
> matrix( c( 11, 11, 34, 35 ), nrow=2 ),
> matrix( c( 14, 15, 58, 58 ), nrow=2 ),
> c( 16, 142 ),
> matrix( c( 19, 19, 94, 95 ), nrow=2 ),
> matrix( c( 19, 20, 127, 127 ), nrow=2 ),
> matrix( c( 22, 22, 112, 113 ), nrow=2 ),
> c( 23, 13 ),
> matrix( c( 26, 27, 81, 81 ), nrow=2 ),
> matrix( c( 31, 32, 153, 153 ), nrow=2 ) )
> xx <- do.call( "rbind", x )
>
> z <- matrix( 1, ncol=249, nrow=240 )
> zz <- matrix( 1, ncol=249, nrow=240 )
>
> for( k in x ) z[k] <- 0
> zz[xx] <- 0
>
> sum( z != zz )
> c( sum( z[,1] != 1 ), sum( zz[,1] != 1 ) )
>
> Somewhere, I must be doing something wrong, or assuming something
> incorrect. I would be very grateful if anybody could point me in the
> right direction.
>
> platform   i386-apple-darwin8.8.1
> arch   i386
> os darwin8.8.1
> system i386, darwin8.8.1
> status
> major  2
> minor  4.1
> year   2006
> month  12
> day18
> svn rev40228
> language   R
> version.string R version 2.4.1 (2006-12-18)
>
> (same results with platform i386-pc-mingw32, R version 2.4.1 and
> platform x86_64-unknown-linux-gnu, R version 2.3.1)
>
> --
> Dr Eric Blanc
> Lecturer in Bioinformatics
> MRC Centre for Developmental Neurobiology
> King's College London
> New Hunt's House Room 4.10B
> Guy's Hospital Campus
> London SE1 1UL
>
> E-mail: [EMAIL PROTECTED]
> Tel: +44 (0)20 7848 6532
> Fax: +44 (0)20 7848 6550
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/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] negative variances

2007-04-11 Thread Dimitris Rizopoulos
In fact this implies that random-effects might not be the way to go 
for your data. When you're using random-effects the marginal 
covariance matrix is of the form:


V = Z D Z^t + Sigma,

where Z is the design matrix for the random-effects, D their 
covariance matrix and Sigma is the covariance matrix for the error 
terms. If the correlation between the repeated measurements of your 
sample units could be explain by a set of random-effects, then D 
should be a positive definite matrix. However, note that V might be 
positive definite even if D it is not, as in your case, which implies 
that the assumption of some common random-effects that the sample 
units share might not be valid.


Alternatively, you could model directly the marginal covariance matrix 
V using the 'correlation' and 'weights' arguments of gls().


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Tu Yu-Kang" <[EMAIL PROTECTED]>

To: 
Sent: Wednesday, April 11, 2007 12:34 PM
Subject: [R] negative variances



Dear R experts,

I had a question which may not be directly relevant to R but I will 
be

grateful if you can give me some advices.

I ran a two-level multilevel model for data with repeated 
measurements over
time, i.e. level-1 the repeated measures and level-2 subjects. I 
could not
get convergence using lme(), so I tried MLwiN, which eventually 
showed the

level-2 variances (random effects for the intercept and slope) were
negative values. I know this is known as Heywood cases in the 
structural
equation modeling literature, but the only discussion on this 
problem in
the literature of multilevel models and random effects models I can 
find is

in the book by Prescott and Brown.

Any suggestion on how to solve this problem will be highly 
appreciated.


Many thanks.

With best regards,

Yu-Kang









__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] argmax

2007-04-04 Thread Dimitris Rizopoulos
check ?which.max(), e.g.,

x <- c(1,4,15,6,7)
which.max(x)


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, April 04, 2007 5:13 PM
Subject: [R] argmax


Hello,

Is there any function that returns the argmax of a vector ?

For example I have the vector x=(1,4,15,6,7)

max(x)=15

I want a function f such that f(x)=3 because this is where max(x) is.

Thank your very much.

P.S. : I know it is a basic question but I have not figured it out by 
myself.
_

ues clics pour retrouver tout ce qui vous intéresse au même endroit.

[[alternative HTML version deleted]]







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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] selection of character

2007-04-04 Thread Dimitris Rizopoulos
one way is the following:

x <- c("10_1", "1_1", "11_1", "2_1", "3_1", "4_1",
"5_1", "6_1", "7_1", "8_1")
#
sapply(strsplit(x, "_"), "[", 2)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Leonardo Lami" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, April 04, 2007 4:11 PM
Subject: [R] selection of character


> Hi all,
>
> I have a simple question:
> I have a character vector like this
>
> [1] "10_1" "1_1"  "11_1" "2_1"  "3_1"  "4_1"  "5_1"  "6_1"  "7_1" 
> "8_1"
> [11] "9_1"  "1_3"  "2_3"  "3_3"  "4_3"  "1_4"  "2_4"  "3_4"  "4_4" 
> "5_4"
> [21] "6_4"  "7_4"  "1_5"  "2_5"  "10_6" "11_6" "12_6" "1_6"  "2_6" 
> "3_6"
> [31] "4_6"  "5_6"  "6_6"  "7_6"  "8_6"  "9_6"  "1_7"  "1_8"  "2_8" 
> "3_8"
> [41] "10_9" "1_9"  "2_9"  "3_9"  "4_9"  "5_9"  "6_9"  "7_9"  "8_9" 
> "9_9"
> [43]  "1_10" "2_10"
>
> and I'd like to have a vector with only the value after the under 
> scor,
> like this:
>
> [1] "1" "1"  "1" "1"  "1"  "1"  "1"  "1"  "1"  "1"
> [11] "1"  "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4"  "4"
> [21] "4"  "4"  "5"  "5"  "6" "6" "6" "6"  "6"  "6"
> [31] "6"  "6"  "6"  "6"  "6"  "6"  "7"  "8"  "8"  "8"
> [41] "9" "9"  "9"  "9"  "9"  "9"  "9"  "9"  "9"  "9"
> [43]  "10" "10"
>
> Is there a simple function to do this?
>
> Thank you for your help
> All the best
>
> Leonardo
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting a list to a data.frame

2007-04-03 Thread Dimitris Rizopoulos
try something like this:

lis <- list(c(1,2,4), c(4,5,2,1), c(3,4,6,3), c(3,1,76,4,2))
##
n.max <- max(sapply(lis, length))
val <- NA # what to fill in
fill <- function(x) c(x, rep(val, n.max - length(x)))
as.data.frame(do.call(rbind, lapply(lis, fill)))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Biscarini, Filippo" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, April 03, 2007 11:28 AM
Subject: [R] converting a list to a data.frame


> Hello,
>
> I have a list with n numerical components of different length (3, 4 
> or 5
> values in each component of the list); I need to export this as a 
> text
> file where each component of the list will be a row and where 
> missing
> values should fill in the blanks due to the different lengths of the
> components of the list.
> I think that as a first step I should convert my list to a data 
> frame,
> but this is not such a simple task to accomplish: I was thinking of 
> the
> following "for" loop:
>
> X<-data.frame(1,1,1,1,1);
>
> for (i in 1:length(list)) {
>
>X[i,]<-unlist(list[[i]]);
>
> }
>
> Unfortunately, when the number of elements in the components of the 
> list
> are lower than 5 (maximum), I get errors or undesired results. I 
> also
> tried with rbind(), but again I couldn't manage to make it accept 
> rows
> of different length.
>
> Does anybody have any suggestions? Working with lists is very nice, 
> but
> I still have to learn how to transfer them to text files for 
> external
> use.
>
> Thnak you,
>
> Filippo Biscarini
> Wageningen University
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] substitute values

2007-04-02 Thread Dimitris Rizopoulos
if your data set is a matrix try this

new.data <- cbind(data, "New Column" = is.na(data[, "Years"]) & data[, 
"Products"] > 20)

whereas if your data set is a data.frame try this

data$"New.Column" <- as.numeric(is.na(data$Years) & data$Products > 
20)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Sergio Della Franca" <[EMAIL PROTECTED]>
To: 
Sent: Monday, April 02, 2007 1:31 PM
Subject: [R] substitute values


> Dear R-Helpers,
>
> I have the following data set(y):
>
> Years   Products
> 1  10
> 2  25
> 3  40
> 4  NA
> 5  35
>23
> 6 NA
> 7 67
> 8 NA
>
> I want to create a new column into my dataset(y) under the following
> conditions:
> if years =NA and products >20 then new column=1 else new column=0;
> to obtain the following results:
>
> Years   Products New Column
> 1  10  0
> 2  25  0
> 3  40  0
> 4  NA 0
> 5  35  0
>23  1
> 6 NA  0
> 7 67   0
> 8 NA  0
>
> Thank you in advance.
>
>
> Serigo Della Franca
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] math-operations

2007-03-30 Thread Dimitris Rizopoulos
513 %/% 100

513 %% 100

check ?"%/%" for more info.


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Schmitt, Corinna" <[EMAIL PROTECTED]>
To: 
Sent: Friday, March 30, 2007 3:34 PM
Subject: [R] math-operations


> Hallo R-experts,
>
> for a function I need to work with the commands "div" and "mod" 
> known
> from Pascal and Ruby. The only help I know is "ceiling()" and 
> "floor()"
> in R. Do "div" and "mod" exist? When yes please send me a little
> example.
>
> In Pascal-Syntax I want:
> 513 div 100 = 5
> 513 mod 100 = 13
>
> How can I get this in R-syntax?
>
> Thanks, Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] composed matrices

2007-03-29 Thread Dimitris Rizopoulos
try this:

A1 <- matrix(1:20, 5, 4)
B1 <- matrix(1:15, 5, 3)
A2 <- matrix(1:8, 2, 4)
B2 <- matrix(1:6, 2, 3)
#
rbind(cbind(A1, B1), cbind(A2, B2))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Eva Ubl" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 29, 2007 1:10 PM
Subject: [R] composed matrices


>I have just started programming in R and so my question might be 
>basic but
> I cant find it in the manual
> I have four matrices A,B,C and D and want them to compose in a big 
> matrix X
> with A in the upper left corner, B in the right upper corner, c 
> below A
> and D below B.
> Thanks for your help
> eva
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Standardization Range

2007-03-28 Thread Dimitris Rizopoulos
you can still use scale() (as you have been told), look at the help 
page for more info, especially at the Arguments section, e.g.,


mat <- matrix(rnorm(100*10), 100, 10)

rng <- apply(mat, 2, range)
scale(mat, scale = rng[2, ] - rng[1, ])

or you could even use apply() directly, e.g.,

apply(mat, 2, function(x) (x - mean(x)) / diff(range(x)) )


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Sergio Della Franca" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, March 28, 2007 11:00 AM
Subject: [R] Standardization Range


> Dear R-Helpers,
>
>
> I want to perform a standardization of a variable with range method.
>
> i.e.:
>
> Standardization (range) ==> (var-min(var))/(max(var)-min(var))
>
>
> Do you konw how can i develop this?
>
> Thank you in advance.
>
>
> Sergio Della Franca
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Replacement in an expression - can't use parse()

2007-03-27 Thread Dimitris Rizopoulos
you could try something like the following (untested):

new.e <- eval(substitute(expression(u1+u2+u3), list(u2 = x, u3 = 1)))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Daniel Berg" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 27, 2007 3:56 PM
Subject: [R] Replacement in an expression - can't use parse()


> Dear all,
>
> Suppose I have a very long expression e. Lets assume, for 
> simplicity, that it is
>
> e = expression(u1+u2+u3)
>
> Now I wish to replace u2 with x and u3 with 1. I.e. the 'new'
> expression, after replacement, should be:
>
>> e
> expression(u1+x+1)
>
> My question is how to do the replacement?
>
> I have tried using:
>
>> e = parse(text=gsub("u2","x",e))
>> e = parse(text=gsub("u3",1,e))
>
> Even though this works fine in this simple example, the use of parse
> when e is very long will fail since parse has a maximum line length
> and will cut my expressions. I need to keep mode(e)=expression since 
> I
> will use e further in symbolic derivation and division.
>
> Any suggestions are most welcome.
>
> Thank you.
>
> Regards,
> Daniel Berg
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Listing function

2007-03-26 Thread Dimitris Rizopoulos
maybe it'd be better to use a data.frame(), e.g.,

dat <- data.frame(name = I("Fred"), wife = I("Mary"), no.children = 3,
cild.ages1 = 4, cild.ages2 = 7, cild.ages3 = 9)
##
new.info <- c(name = "Barney", wife = "Liz", no.children=2,
cild.ages1 = 3, cild.ages2 = 5, cild.ages3 = NA)

rbind(dat, new.info)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Schmitt, Corinna" <[EMAIL PROTECTED]>
To: 
Sent: Monday, March 26, 2007 3:26 PM
Subject: [R] Listing function


> Hallo,
>
> I build a list by the following way:
>
> Lst = list(name="Fred", wife="Mary", no.children=3, 
> cild.ages=c(4,7,9))
>
> I know how I can extract the information one by one. But now I want 
> to
> add a new entry which looks like
>
> name="Barney", wife="Liz", no.children=2, cild.ages=c(3,5)
>
> How can I add this information to Lst without overwriting the first
> entry?
> How can I then extract the corresponding information if I have both
> entries in Lst?
>
> Thanks for helping,
>
> Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] for loop in assigning column names

2007-03-21 Thread Dimitris Rizopoulos
try

df.new <- cbind(df, ObJeCt[1:10])
names(df.new) <- c(names(df), paste("St", 1:10, sep = ""))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Luis Ridao Cruz" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, March 21, 2007 4:14 PM
Subject: [R] for loop in assigning column names


> R-help,
>
> I have a data frame (df) and I want to add some columns whose names
> should correspond to the "i" index in the loop below.
>
> for(i in 1:10)
> {
> df$eval(paste("St", as.character(i), sep = "" ))  <- ObJeCt[i]
> }
>
> An error message comes out :
>
> "Error: attempt to apply non-function"
>
> How can I get around this?
>
> I could do something like :
>
> df$St2 <- NA
> df$St3 <- NA
> dft$St4 < -NA
> ..
>
> and afterwards assign the results of the loop above
> to the columns df$St2,df$St3,,,
>
> The problem is that my object "ObJeCt[i]" may change in size
> and definition and therefore a way to systematize the task would
> be desirable.
>
> Thanks in advance
>
>> version
>   _
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  4.1
> year   2006
> month  12
> day18
> svn rev40228
> language   R
> version.string R version 2.4.1 (2006-12-18)
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Select the last two rows by id group

2007-03-20 Thread Dimitris Rizopoulos
you can use the following (based on Gabor's answer):

math <- c(80,75,70,65,65,70)
reading <- c(65,70,88,NA,90,NA)
id <- c('001','001','001','002','003','003')
score <- data.frame(id, reading, math)

#

# it might be useful to sort first
# score <- score[order(score$id), ]

score
score[unlist(tapply(row.names(score), score$id, tail, n = 2)), ]

look at ?tail() for more info.

I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Lauri Nikkinen" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 20, 2007 3:33 PM
Subject: [R] Select the last two rows by id group


> Hi R-users,
>
> Following this post 
> http://tolstoy.newcastle.edu.au/R/help/06/06/28965.html ,
> how do I get last two rows (or six or ten) by id group out of the 
> data
> frame? Here the example gives just the last row.
>
> Sincere thanks,
> Lauri
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] abline within data range

2007-03-20 Thread Dimitris Rizopoulos
try this:

x <- rnorm(200, 35, 5)
y <- rnorm(200, 0.87, 0.12)
###
lmObj <- lm(y ~ x)
xs <- range(x)
ys <- predict(lmObj, newdata = data.frame(x = xs))
plot(x, y, pch = 17, bty = "l")
lines(xs, ys, col = "red", lty = 2, lwd = 2)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Nguyen Dinh Nguyen" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 20, 2007 12:32 PM
Subject: [R] abline within data range


> Dear R helpers,
>
> I would like to have abline,  for a lm model for
> example, lying within data range. Do you know how to
> get it?
>
> Thank in advance
>
> Nguyen D Nguyen
>
> #CODE
> x<- rnorm(200, 35,5)
> y<- rnorm(200, 0.87,0.12)
> plot(y~x, xlim=c(0,50), pch=17, bty="l")
> abline(lm(y~x))
>
> # I would like abline is between min(x) and max(x)
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] character to numeric conversion

2007-03-19 Thread Dimitris Rizopoulos
you could give a try to strsplit(), e.g.,

strg <- "0.E-38, 2.096751179214927596171268230, 
3.678944959657480671183123052"
strg <- paste(rep(strg, 5000), collapse = ", ")
##
f.out <- factor(strsplit(strg, ", ")[[1]])
n.out <- as.numeric(levels(f.out))[as.integer(f.out)]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Robin Hankin" <[EMAIL PROTECTED]>
To: "RHelp help" 
Sent: Monday, March 19, 2007 10:18 AM
Subject: [R] character to numeric conversion


> Hi.
>
> Is there a straightforward way to convert a character string
> containing comma-delimited
> numbers  to a numeric vector?
>
> In my application, I use
>
> system(executable.string, intern=TRUE)
>
> which returns a string like
>
> "[0.E-38, 2.096751179214927596171268230,
> 3.678944959657480671183123052, 4.976528845643001020345216157,
> 6.072390165503099343887569007, 7.007958550337542210168866070,
> 7.807464185827177139302778736, 8.486139455817034846608029724,
> 9.053706780665060873259065771, 9.516172308326877463284426111,
> 9.876856047379733199590985269, 10.13695826383869052536062804,
> 10.29580989588667234885515374, 10.35092785255025551187463209,
> 10.29795676261278695909972578, 10.13052574735986793562227138,
> 9.839990935943625006580521345, 9.414977153151389385186358494,
> 8.840562526759586215404890348, 8.096830792651667245232639586,
> 7.156244887881612948153311800, 5.978569259122249264778017262,
> 4.499809670330265066808481929, 2.602689685444383764768503589, 
> 0.E-38]"
>
>
> (the output is a single line).   In a big run, the string may 
> contain
> 10^5 or possibly 10^6 numbers.
>
> What's the recommended way to convert this to a numeric vector?
>
>
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] abs(U) > 0 where U is a vector?

2007-03-14 Thread Dimitris Rizopoulos
try: all(U > 0)


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Benjamin Dickgiesser" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, March 14, 2007 11:35 AM
Subject: [R] abs(U) > 0 where U is a vector?


> Hi,
>
> I am looking for a way to compare if every element of a vector is > 
> 0.
>
> i.e.
> while(abs(U) > 0)
> {
>
> ..
> }
>
> is there a function for this or do I have to write one?
>
> I'd appreciate your help!
>
> Benjamin
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] selecting rows with more than x occurrences in a given column(data type is names)

2007-03-13 Thread Dimitris Rizopoulos
try this:

set.seed(123)
all.data <- data.frame(name = sample(c("Joe", "Elen", "Jane", "Mike"), 
8, TRUE),
x = rnorm(8), y = runif(8))
##
tab.nams <- table(all.data$name)
nams <- names(tab.nams[tab.nams >= 2])
all.data[all.data$name %in% nams, ]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Mike Jasper" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 13, 2007 3:38 PM
Subject: [R] selecting rows with more than x occurrences in a given 
column(data type is names)


> Despite a long search on the archives, I couldn't find how to do 
> this.
> Thanks in advance for what is likely a simple issue.
>
> I have a data set where the first column is name (i.e., 'Joe Smith',
> 'Jane Doe', etc). The following columns are data associated with 
> that
> person. I have many people with multiple rows. What I want is to get 
> a
> new data frame out with only the people who have more than x
> occurrences in the first column.
>
> Here's what I've done, that's not working:
>
> Let's call my old data.frame "all.data"
>
> table(all.data$names)>10
>
> I get a list of names and TRUE/FALSE values. I then want to make a
> list of the TRUEs and pass that to some subset type command like
>
> dup.names=table(all.data$names)>10
>
> new.data=(all.data[all.data$names==dup.names,])
>
> That's not working because the dimensions are wrong (I think). But
> even when I tried to do part of it manually (to troubleshoot) like
> this
>
> dup.names=c('Joe Smith','Jane Doe','etc')
>
> I got warnings and it didn't work correctly. There must be a simple
> way to do this that I'm just not seeing. Thanks.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Removing duplicated rows within a matrix, with missing data as wildcards

2007-03-09 Thread Dimitris Rizopoulos
you could also try something like the following:

x <- matrix(c(1, NA, 3, NA, 2, 3, 1, 3, 2, 2, 1, 3, 1, NA, 2, 2, 1, 
3), ncol=3, byrow=TRUE)

wildcardVals <- 1:3 # possible wildcard values
ind <- complete.cases(x)
nc <- ncol(x)
nr <- nrow(x[ind, ])
nwld <- length(wildcardVals)
posb <- apply(x[!ind, , drop = FALSE], 1, function(y){
out <- matrix(y, nwld, nc, by = TRUE)
out[, is.na(y)] <- wildcardVals
t(out)
})
posb <- matrix(c(posb), ncol = nc, by = TRUE)
keep.ind <- duplicated(rbind(x[ind, ], posb))
keep.ind[-(1:nr)] <- apply(matrix(keep.ind[-(1:nr)], nc = nwld, by = 
TRUE),
1, function(x) if(any(x)) rep(TRUE, length(x)) else x)
out <- rbind(x[ind, ], matrix(rep(x[!ind, ], each = nwld), nc = nc))
unique(out[!keep.ind, ])


I hope it works ok.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm

- Original Message - 
From: "stacey thompson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; 
Cc: <[EMAIL PROTECTED]>
Sent: Friday, March 09, 2007 3:09 PM
Subject: Re: [R] Removing duplicated rows within a matrix,with missing 
data as wildcards


> Hi H.,
>
> Your response has improved the clarity of my thinking.  Kind thanks.
> Also, your use of seq_len() prompted me to update from R version 
> 2.3.1
> on this machine.
>
> For your matrix
>
> > x <- matrix(c(1, NA, 3, NA, 2, 3), ncol=3, byrow=TRUE)
> > x
>  [,1] [,2] [,3]
> [1,]1   NA3
> [2,]   NA23
>
> I would want to delete either x[1,] or x[2,] but not both.
> Practically, your "removeLooseDupRows(x)"
>
> removeLooseDupRows <- function(x)
> {
>   if (nrow(x) <= 1)
>   return(x)
>   ii <- do.call("order",
> args=lapply(seq_len(ncol(x)),
> function(col) x[ , col]))
>   dup_index <- logical(nrow(x))
>   i0 <- -1
>   for (k in 1:length(ii)) {
>   i <- ii[k]
>   if (any(is.na(x[i, ]))) {
>   if (i0 == -1)
>   next
>   if (any(x[i, ] != x[i0, ], na.rm=TRUE))
>   next
>   dup_index[i] <- TRUE
>   } else {
>   i0 <- i
>   }
>   }
>   x[!dup_index, ]
> }
>
> should leave no such ambiguous cases for my data, as the nrow(x) are
> very high with few NA in each x.  For example, a row of (1, 2, 3) is
> very likely to exist in my data.
>
> However, to find the row numbers of any remaining ambiguous matches,
> should they exist, using example:
>
>> x <- matrix(c(1, NA, 3, NA, 2, 3, 1, 3, 2, 2, 1, 3, 1, NA, 2, 2, 1, 
>> 3), ncol=3, byrow=TRUE)
>> x
> [,1] [,2] [,3]
> [1,]1   NA3
> [2,]   NA23
> [3,]132
> [4,]213
> [5,]1   NA2
> [6,]213
>
> after your suggested
>
>> removeLooseDupRows(x)
> [,1] [,2] [,3]
> [1,]1   NA3
> [2,]   NA23
> [3,]132
> [4,]213
> [5,]213
>
>> q <- removeLooseDupRows(unique(x))
>> q
> [,1] [,2] [,3]
> [1,]1   NA3
> [2,]   NA23
> [3,]132
> [4,]213
>
> I could
>
>> # ambiguous matches in matrix form
>> apply(q, 1, function(row1) apply(q, 1, function(row2) 
>> all(is.na(row1) | is.na(row2) | row1==row2)))
>
>  [,1]  [,2]  [,3]  [,4]
> [1,]  TRUE  TRUE FALSE FALSE
> [2,]  TRUE  TRUE FALSE FALSE
> [3,] FALSE FALSE  TRUE FALSE
> [4,] FALSE FALSE FALSE  TRUE
>
>> # indices of ambiguous matches
>> m <- which(apply(q, 1, function(row1) apply(q, 1, function(row2) 
>> all(is.na(row1) | is.na(row2) | row1==row2))), arr=T)
>> m
> row col
> [1,]   1   1
> [2,]   2   1
> [3,]   1   2
> [4,]   2   2
> [5,]   3   3
> [6,]   4   4
>
>> #put in order and omit duplicates
>> m2 <- unique(t(apply(m, 1, sort)))
>> m2
> [,1] [,2]
> [1,]11
> [2,]12
> [3,]22
> [4,]33
> [5,]44
>
>> # show the ambiguous matches
>> m2[m2[,1]!=m2[,2], drop=F]
> [1] 1 2
>
> ...and procede from there.
>
> This solution came from another helpful "R-help" respondant to my
> poorly-defined problem.
>
> Appreciative thanks to everyone for your instructive help.
>
> Cheers,
> stacey
>
> -- 
> -stacey lee thompson-
> Stagiaire post-doctorale
> Institut de recherche en biologie végétale
> Université de 

Re: [R] Query about using setdiff

2007-03-07 Thread Dimitris Rizopoulos
try something along these lines (untested):

DF1[DF1$id %in% DF2$id2, c("val1", "val2")]
DF1[!DF1$id %in% DF2$id2, c("val1", "val2")]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting lalitha viswanath <[EMAIL PROTECTED]>:

> Hi
> I have two dataframes
> names(DF1) = c("id", "val1", "val2");
>
> names(DF2) = c("id2");
>
> Ids in DF2 are a complete subset of those in DF1
>
> How can I extract entries from DF1 where id NOT IN
> DF2.
>
> I tried setdiff(DF1, DF2); setdiff(DF1$id, DF2$id),
> etc.
> Although the latter eliminates the ids as required, I
> dont know how to extract val1 and val2 for the
> resultant set.
>
>
> Thanks
> Lalitha
>
>
>
> 
> 8:00? 8:25? 8:40? Find a flick in no time
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Passing command line parameters to a script

2007-03-06 Thread Dimitris Rizopoulos
probably you're looking for ?commandArgs().


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "akintayo holder" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, March 06, 2007 9:11 AM
Subject: [R] Passing command line parameters to a script


> Hi,
> Does any one know if it is possible to create an R script that can 
> use
> command line parameters. I can execute an R script from the command 
> line,
> but I  cannot figure out how to pass parameters to the script. The 
> only
> resources I have found seem somewhat involved or incomplete.
>
> Any help is appreciated.
> Akintayo
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] count the # of appearances...

2007-03-01 Thread Dimitris Rizopoulos
?table

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "bunny , lautloscrew.com" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 01, 2007 3:20 PM
Subject: [R] count the # of appearances...


> Hi there,
>
> is there a possibility to count the number of appearances of an
> element in a vector ?
> i mean of any given element.. deliver all elements which are exactly
> xtimes in this vector ?
>
> thx in advance !!
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Additional args to fun in integrate() not found?

2007-02-27 Thread Dimitris Rizopoulos
you need 'p = p' in the integrate() call; try this version:

gedCDF <- function (yvec, p = 2, mu = 0, scale = 1, numint = 0) {
k <- sqrt(2)
# k <- 1
scale <- scale*k
zvec <- (yvec - mu) / scale
cdf <- numeric(length(zvec))
for (i in seq(zvec)) {
z <- zvec[i]
cdf[i] <- if (numint == 0) {
if (z <= 0) {
0.5 * (1 - 1/gamma(1/p) * Igamma((1/p), (-z)^p,
lower = TRUE))
} else {
1 - (0.5 * (1 - 1/gamma(1/p) * Igamma((1/p), (z)^p,
lower = TRUE)))
}
} else {
integrate(geddenstandard, lower = -35, upper = z,
rel.tol = 100*.Machine$double.eps, p = p)$value
}
}
cdf
}

geddenstandard <- function (z, p) {
p / (2 * gamma(1/p)) * exp(-abs(z)^p)
}

###

gedCDF(c(1,2,3,4,5), numint=1)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Sergey Goriatchev" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, February 27, 2007 10:49 AM
Subject: [R] Additional args to fun in integrate() not found?


> Hello, fellow Rdicts,
>
> I have  the code for the program below. I need to integrate a 
> function
> of "x" and "p". I use integrate to integrate over "x" and pass "p" 
> as
> an additional argument. "p" is specified and given default value in
> the argument list. Still, integrate() cannot read "p", unless I
> explicitly insert a numeric value in the integrate() argument list.
> And when I do that, I get the right result, but still some warnings.
>
> Please, help me with these problems:
> 1) why is "p" not recognized?
> 2) what are these warning messages?
>
> PROGRAM CODE:
> ---
>
> #THIS LIBRARY IS NEEDED FOR THE INCOMPLETE GAMMA FUNCTION
>
> library(zipfR)
>
> #
>
> gedCDF = function(yvec, p=2, mu=0, scale=1, numint=0)
> {
>
> #-
> #Setting k to sqrt(2) and the GED with p=2 coincides with standard 
> normal.
> #Set k=1 and GED with p=1 coincides with Laplace.
>
> k<-sqrt(2)
> #k<-1
> scale<-scale*k
>
> zvec<-(yvec-mu)/scale
> cdf<-matrix(0, length(zvec),1)
>
> for(i in 1:length(zvec))
> {
> z<-zvec[i]
>
> if(numint==0)
> {
> if(z<=0)
> {
> t<-0.5*(1-1/gamma(1/p)*Igamma((1/p),(-z)^p,lower=TRUE))
> }
> else
> {
> t<-1-(0.5*(1-1/gamma(1/p)*Igamma((1/p),(z)^p,lower=TRUE )))
> }
> }
> else
> {
> t<-integrate(geddenstandard, -35, z, subdivisions=1000,
> rel.tol=100*.Machine$double.eps, abs.tol=rel.tol,
> stop.on.error=TRUE, keep.xy=FALSE, aux=NULL,p)
> }
> cdf[i]<-t
> }
> cdf
> }
>
> #-
> geddenstandard = function(z,p)
> {
> f<-p/(2*gamma(1/p))*exp(-abs(z)^p)
> }
> ---
>
> If I run with this definition I get the following error message and 
> abort:
>> gedCDF(c(1,2,3,4,5), numint=1)
> Error in eval(expr, envir, enclos) : ..1 used in an incorrect 
> context,
> no ... to look in
>
> If I replace "p" in integrate() with 2, I get correct answers, but
> still some warning messages:
>
>> gedCDF(c(1,2,3,4,5), numint=1)
> [[1]]
> [1] 0.8413447
>
> [[2]]
> [1] 0.9772499
>
> [[3]]
> [1] 0.9986501
>
> [[4]]
> [1] 0.683
>
> [[5]]
> [1] 0.997
>
> Warning messages:
> 1: number of items to replace is not a multiple of replacement 
> length
> 2: number of items to replace is not a multiple of replacement 
> length
> 3: number of items to replace is not a multiple of replacement 
> length
> 4: number of items to replace is not a multiple of replacement 
> length
> 5: number of items to replace is not a multiple of replacement 
> length
>
> ---
> Do I get these warnings because I define cdf as a matrix and the
> output-cdf is a list?
>
> Please, help me with these!
> Email to my gmail account, please: [EMAIL PROTECTED]
>
> THanks in advance
> Sergey
>
> __
> R-help@stat.

Re: [R] Test of Presence Matrix HOWTO?

2007-02-26 Thread Dimitris Rizopoulos
you can use something like the following:

a <- list("A","B","C","D")
b <- list("A","B","E","F")
c <- list("A","C","E","G")

#

abc <- list(a, b, c)
unq.abc <- unique(unlist(abc))

out.lis <- lapply(abc, "%in%", x = unq.abc)
out.lis
lapply(out.lis, as.numeric)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Johannes Graumann" <[EMAIL PROTECTED]>
To: 
Sent: Monday, February 26, 2007 4:25 PM
Subject: [R] Test of Presence Matrix HOWTO?


> Hello,
>
> Imagine 3 lists like so:
>
>> a <- list("A","B","C","D")
>> b <- list("A","B","E","F")
>> c <- list("A","C","E","G")
>
> What I need (vennDiagram) is a matrix characterizing with 1 or 0 
> whether any
> given member is present or not like so:
> x1 x2 x3
> [1,]  1  1  1
> [2,]  1  1  0
> [3,]  1  0  1
> [4,]  1  0  0
> [5,]  0  1  1
> [6,]  0  1  0
> [7,]  0  0  1
>
> (where the rows represent "A"-"G" and the columns a-c, 
> respectively).
>
>> table(c(a,b,c))
> will give me a quick answer for the "1 1 1" case, but how to deal 
> with the
> other cases efficiently without looping over each string and looking 
> for
> membership %in% each list?
>
> Thanks for enlightening the learning,
>
> Joh
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cross-tabulations next to each other

2007-02-22 Thread Dimitris Rizopoulos
maybe cbind() is close to what you're looking for, e.g.,

tb1 <- table(x, y)
tb2 <- table(x, z)

cbind(tb1, tb2)


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Charilaos Skiadas" <[EMAIL PROTECTED]>
To: "R-Mailingliste" 
Sent: Thursday, February 22, 2007 4:01 PM
Subject: [R] Cross-tabulations next to each other


>I have the following relatively simple problem. Say we have three
> factors, and we want to create a cross-tabulation against each of 
> the
> other two:
>
> x <- factor(rbinom(5, 1, 1/2))
> y <- factor(rbinom(5, 1, 1/2))
> z <- factor(rbinom(5, 1, 1/2))
> table(x,y)
> table(x,z)
>
> This looks like:
>
>y
> x   0 1
>   0 2 0
>   1 1 2
>
>z
> x   0 1
>   0 1 1
>   1 2 1
>
> I would like to get (surely this will look a mess in non-monospaced
> fonts):
>
>yz
> x   0 1  0 1
>   0 2 0  1 1
>   1 1 2  2 1
>
> Or something along those lines. Then I would like to convert this to
> a LaTeX table, in the obvious sort of way.
>
> I couldn't find an answer with a quick look through the
> documentation. Are these two things already done, before I try to
> roll my own?
>
> Haris Skiadas
> Department of Mathematics and Computer Science
> Hanover College
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] List filtration

2007-02-22 Thread Dimitris Rizopoulos
try this:

lis. <- lapply(lis, function(x) if (length(ind <- grep("^IPI", x))) 
x[ind[1]] else NULL)
lis.[!sapply(lis., is.null)]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Johannes Graumann" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 22, 2007 3:33 PM
Subject: [R] List filtration


> Hello R-ologists,
>
> Imagine you have a list "list" like so:
>
>>list
> [[1]]
> [1] "IPI00776145.1" "IPI00776187.1"
>
> [[2]]
> [1] "Something" "IPI00807764.1" "IPI00807887.1"
>
> [[3]]
> [1] "IPI00807764.1"
>
> [[4]]
> [1] "Somethingelse"
>
> What I need to achieve is a filtered list "list2" like so:
>
>>list2
> [[1]]
> [1] "IPI00776145.1"
>
> [[2]]
> [1] "IPI00807764.1"
>
> [[3]]
> [1] "IPI00807764.1"
>
> So:
> - if sublist-entry 1 start with "^IPI" make it the list-entry.
> - otherwise chose the first "^IPI" sublist-entry present.
> - delete the list-entry if not "^IPI" sublist-entry present.
>
> Can anybody nudge me towards an elegant solution without looping - I 
> have
> LOTS of entries to process ...
>
> Thanks for your Teachings,
>
> Joh
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Combining tapply() and cor.test()?

2007-02-22 Thread Dimitris Rizopoulos
one approach is the following:

dat <- data.frame(
Period = as.Date(rep(c("1996-07-31", "1996-08-31", "1996-09-30"), 
each = 15)),
Returns = rnorm(45),
MFR.Factor = runif(45)
)

###

do.call(rbind, lapply(split(dat[c("Returns", "MFR.Factor")], 
dat$Period),
function (x) {
cr <- cor.test(x$Returns, x$MFR.Factor, method = "spearman")
c("estimate" = cr$estimate, "p.value" = cr$p.value)
}))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Sergey Goriatchev" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 22, 2007 2:35 PM
Subject: [R] Combining tapply() and cor.test()?


> Hello, fellow R-users.
>
> Let me describe the setup first. I have a data.frame, a sample of
> which is reported below:
>
>   Company.Name  Periods  Returns   MFR.Factor
> 350 Wartsila Oyj A  1996-07-31  6.82 0.02
> 351Custodia Holding AG  1996-07-31  4.15-0.02
> 352   Wartsila Oyj   1996-07-31  7.73 0.09
> 353   GEA Group AG   1996-07-3110.12 0.04
> 354LEGRAND ORD 1996-07-31 -7.46-0.20
> 355 Mayr-Melnhof Karton AG 1996-07-31 4.71-0.05
> 356GEVAERT NPV  1996-08-30  NA  NA
> 357NOKIA K FMA2.50  1996-08-30 7.65 0.03
> 358   Altadis S.A. 1996-08-30 7.65 0.55
> 359   Metrovacesa S.A. 1996-08-30 4.55-0.17
> 360   Oce N.V.  1996-08-309.43 0.23
>
> The variable "Periods" is a date object, shows the month.
> Variables "Returns" and "MFR.Factor" are numeric.
> For each month the number of Returns and MFR.Factors varies, 
> sometimes
> it is 350, sometimes 320 etc.
>
> What I need is to use cor.test(Returns, MFR.Factor,...) for each
> month, and produce a dataframe with columns: "Period", 
> "cor.estimate",
> "p.value".
>
> The simplest way would be with tapply() using variable "Period" as a
> factor, but tapply() only applies FUN to just one cell.
>
> What is the most painless way to achieve my objective?
>
> Thank you in advance for your help!
>
> Best,
> Sergey
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] simple question on one-sided p-values for coef() on output of lm()

2007-02-21 Thread Dimitris Rizopoulos
Quoting Ranjan Maitra <[EMAIL PROTECTED]>:

> Yes, of course! Thank you. So, I guess the answer is that R itself   
> can not be made to do so directly.
>
> Many thanks for confirming this.
>
> Sincerely,
> Ranjan
>
> On Wed, 21 Feb 2007 20:23:55 + (GMT) Prof Brian Ripley   
> <[EMAIL PROTECTED]> wrote:
>
>> On Wed, 21 Feb 2007, Ranjan Maitra wrote:
>>
>> > I was wondering if it is possible to get the p-values for one-sided
>> > tests on the parameters of a linear regression.
>> >
>> > For instance, I use lm() and store the result in an object. lm() gives
>> > me a matrix, using summary() and coef() on which gives me a matrix
>> > containing the coefficients, the standard errors, the t-statistics and
>> > the two-sided p-values by default. Can I get it to provide me with
>> > one-sided p-values (something like alternative less than or greater
>> > than)?
>>
>> Not 'it', but you can easily do the calculation yourself from the output.
>> E.g.
>>
>> example(lm)
>> s <- summary(lm.D90)
>> pt(coef(s)[, 2], s$df[2], lower=FALSE) # or TRUE

I think it should be

pt(coef(s)[, 3], s$df[2], lower=FALSE) # or TRUE
  ^

Best,
Dimitris


>>
>> --
>> Brian D. Ripley,  [EMAIL PROTECTED]
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford, Tel:  +44 1865 272861 (self)
>> 1 South Parks Road, +44 1865 272866 (PA)
>> Oxford OX1 3TG, UKFax:  +44 1865 272595
>>
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Omiting repeated values

2007-02-21 Thread Dimitris Rizopoulos
x <- sample(1:3, 20, TRUE)
x

# do you mean

unique(x)

# or

rle(x)$values


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting stat stat <[EMAIL PROTECTED]>:

> Dear all R users,
>
>   Is there any function to omit repeated values in a vector? Your   
> help will be highly appreciated.
>
>   Thanks
>   stat
>
>
> -
>  Here’s a new way to find what you're looking for - Yahoo! Answers
>   [[alternative HTML version deleted]]
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] testing slopes

2007-02-20 Thread Dimitris Rizopoulos
two options are to use an offset term or the linear.hypothesis()  
function from package car, e.g.,

y <- rnorm(100, 2 - 1 * (x <- runif(100, -3, 3)), 3)

fit0 <- lm(y ~ 1 + offset(-x))
fit1 <- lm(y ~ x)
anova(fit0, fit1)

library(car)
linear.hypothesis(fit1, c("x = -1"))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Indermaur Lukas <[EMAIL PROTECTED]>:

> Hello
> Instead of testing against 0 i would like to test regression slopes   
> against -1. Any idea if there's an R script (package?) available.
>
> Thanks for any hint.
> Cheers
> Lukas
>
>
>
>
> °°°
> Lukas Indermaur, PhD student
> eawag / Swiss Federal Institute of Aquatic Science and Technology
> ECO - Department of Aquatic Ecology
> Überlandstrasse 133
> CH-8600 Dübendorf
> Switzerland
>
> Phone: +41 (0) 71 220 38 25
> Fax: +41 (0) 44 823 53 15
> Email: [EMAIL PROTECTED]
> www.lukasindermaur.ch
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] list of data frame objects

2007-02-18 Thread Dimitris Rizopoulos
try something like the following (untested):

objs <- ls()
sapply(objs, function(obj) inherits(get(obj), "data.frame"))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Tim McDonald <[EMAIL PROTECTED]>:

> Hi Folks,
>
> I need to extract the list of all my data frame objects. With 
> objects() I can list all objects and was hoping to use something   
> like the following:
>
> objects()[is.data.frame(objects())] to extracts all my objects that   
> are data frame...
>
> What am I doing wrong?
>
> Thanks - Tim
>
>
> -
> Any questions?  Get answers on any topic at Yahoo! Answers. Try it now.
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Generating MVN Data

2007-02-13 Thread Dimitris Rizopoulos
you probably want to use mvrnorm() from package MASS, e.g.,

library(MASS)
mu <- c(-3, 0, 3)
Sigma <- rbind(c(5,3,2), c(3,4,1), c(2,1,3))
x <- mvrnorm(1000, mu, Sigma, empirical = TRUE)

colMeans(x)
var(x)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Rauf Ahmad" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, February 13, 2007 3:14 PM
Subject: [R] Generating MVN Data


> Dear All
>
> I want to generate multivariate normal data in R for a given 
> covariance
> matrix, i.e. my generated data must have the given covariance 
> matrix. I
> know the rmvnorm command is to be used but may be I am failing to
> properly assign the covariance matrix.
>
> Any help will be greatly appreciated
>
> thanks.
>
> M. R. Ahmad
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Near function?

2007-02-11 Thread Dimitris Rizopoulos
maybe you could try something along these lines:

x <- c(1, 3, 2, 5, 11)
thr <- 3
###
ind <- t(combn(x, 2))
unique(c(ind[abs(ind[, 1] - ind[, 2]) <= thr, ]))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Bart Joosen <[EMAIL PROTECTED]>:

> All,
>
> thanks for your help.
>
> Dieter,
>
> thanks, it's a different way of tackling the problem.
> But I still need a for loop to scroll throug the list?
>
> For example:
> c(1,2,3,5,)
> and a threshold of 3, then c(1,5) should remain. If I make an   
> integer with the difference between each element and the previous   
> element,
> then 5 should be eliminated, while it shouldn't.
>
> Or am I wrong with this assumption?
>
> Thanks anyway
>
> Bart
>
>
>>
>> Hi,
>>
>> I have an integer which is extracted from a dataframe, which is sorted by
> another column of the dataframe.
>> Now I would like to remove some elements of the integer, which are near to
> others by their value. For example:
>> integer: c(1,20,2,21) should be c(1,20).
>
> ...
>> Sorting the integer is not an option, the order is important.
>
> Why not? It's extremely efficient for large series and the only method that
> would work with large array. The idea: Keep the indexes of the sort   
> order, mark
> the "near others" for example making their index NA, and restore   
> original order.
> No for-loop needed.
>
> Dieter
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Confidence intervals of quantiles

2007-02-05 Thread Dimitris Rizopoulos
you could use the Bootstrap method, using package 'boot', e.g.,

library(boot)

f.quantile <- function(x, ind, ...){
quantile(x[ind], ...)
}

###

x <- rgamma(750, 2)
quant.boot <- boot(x, f.quantile, R = 1000, probs = c(0.025, 0.25, 
0.5, 0.75, 0.975))
lapply(1:5, function(i) boot.ci(quant.boot, c(0.90, 0.95), type = 
c("perc", "bca"), index = i))

y <- rgamma(150, 2)
quant.boot <- boot(y, f.quantile, R = 1000, probs = c(0.025, 0.25, 
0.5, 0.75, 0.975))
lapply(1:5, function(i) boot.ci(quant.boot, c(0.90, 0.95), type = 
c("perc", "bca"), index = i))


However, you should be a little bit careful with Bootstrap if you wish 
to obtain CIs for extreme quantiles in small samples.

I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Mike White" <[EMAIL PROTECTED]>
To: 
Sent: Monday, February 05, 2007 2:47 PM
Subject: [R] Confidence intervals of quantiles


> Can anyone please tell me if there is a function to calculate 
> confidence
> intervals for the results of the quantile function.
> Some of my data is normally distributed but some is also a squewed
> distribution or a capped normal distribution. Some of the data sets 
> contain
> about 700 values whereas others are smaller with about 100-150 
> values, so I
> would like to see how the confidence intervals change for the 
> different
> distributions and different data sizes.
>
> Thanks
> Mike White
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need help writing a faster code

2007-02-01 Thread Dimitris Rizopoulos
the following seems to be a first improvement:

m <- 2000
n <- 5000
A <- matrix(rnorm(2*m), ncol=2)
B <- matrix(rnorm(2*n), ncol=2)
W1 <- W2 <- matrix(0, m, n)

##
##

g1 <- function(x, y){
theta <- atan((y[2] - x[2]) / (y[1] - x[1]))
theta + 2*pi*(theta < 0)
}

invisible({gc(); gc()})
system.time(for (i in 1:m) {
W1[i, ] <- apply(B, 1, y = A[i,], function(x, y) g1(y, x))
})

##

g2 <- function(x){
out <- tB - x
theta <- atan(out[2, ] / out[1, ])
theta + 2*pi*(theta < 0)
}

tB <- t(B)
invisible({gc(); gc()})
system.time(for (i in 1:m) {
W2[i, ] <- g2(A[i, ])
})

## or

invisible({gc(); gc()})
system.time(W3 <- t(apply(A, 1, g2)))

all.equal(W1, W2)
all.equal(W1, W3)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Ravi Varadhan" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 01, 2007 4:10 PM
Subject: [R] Need help writing a faster code


> Hi,
>
>
>
> I apologize for this repeat posting, which I first posted yesterday. 
> I would
> appreciate any hints on solving this problem:
>
>
>
> I have two matrices A (m x 2) and B (n x 2), where m and n are large
> integers (on the order of 10^4).  I am looking for an efficient way 
> to
> create another matrix, W (m x n), which can be defined as follows:
>
>
>
> for (i in 1:m){
>
> for (j in 1:n) {
>
> W[i,j] <- g(A[i,], B[j,])
>
> } }
>
> where g(x,y) is a function that takes two vectors and returns a 
> scalar.
>
>
>
> The following works okay, but is not fast enough for my purpose.  I 
> am sure
> that I can do better:
>
>
>
> for (i in 1:m) {
>
> W[i,] <- apply(B, 1, y=A[i,], function(x,y) g(y,x))
>
> }
>
>
>
> How can I do this in a faster manner? I attempted "outer", 
> "kronecker",
> "expand.grid", etc, but with no success.
>
>
>
> Here is an example:
>
>
>
> m <- 2000
>
> n <- 5000
>
> A <- matrix(rnorm(2*m),ncol=2)
>
> B <- matrix(rnorm(2*n),ncol=2)
>
> W <- matrix(NA, m, n)
>
>
>
> for (i in 1:m) {
>
> W[i,] <- apply(B, 1, y=A[i,], function(x,y) g(y,x))
>
> }
>
>
>
> g <- function(x,y){
>
> theta <- atan((y[2]-x[2]) / (y[1] - x[1]))
>
> theta + 2*pi*(theta < 0)
>
> }
>
>
>
> Thanks for any suggestions.
>
>
>
> Best,
>
> Ravi.
>
>
>
>
>
>
>
> 
> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: [EMAIL PROTECTED]
>
> Webpage: 
> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
>
>
>
> 
> 
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Index mapping on arrays

2007-02-01 Thread Dimitris Rizopoulos
probably you want something like the following:

A[cbind(rep(1, length(x)), x, y)]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Demi Anderson" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 01, 2007 2:34 PM
Subject: [R] Index mapping on arrays


> Dear R-community,
>
> I have some trouble with index mappings for arrays. If, for example,
> I have the array
>
> R> A <- array(1:9, c(3,3,2))
>
> and two index mappings both of same size
>
> R> x <- c(2, 3)
> R> y <- c(1, 2)
>
> Now I want to access the elements (A[1, x[i], y[i]])_i of A, i.e.
> A[1, x[1], y[1]] = A[1, 2, 1] and A[1, x[2], y[2]] = A[1, 3, 2].
>
> If I use
>
> R> A[1, x, y]
>
> I would get every combinations of indices of all elements of x and y
> i.e. A[1, x[1], y[1]], A[1, x[1], y[2]], A[1, x[2], y[1]] and A[1,
> x[2], y[2]]. But how can I access the elements (A[1, x[i], y[i]])_i.
> My arrays dimensions are actually large in the second
> component (for example the dimension might be 10*1*10) so I'm
> looking for a method avoiding loops.
>
> The question is probably trivial for you, but I just could not
> figure it out. So sorry for bugging you and many thanks in advance
> for any help.
>
> Best wishes, Demi Anderson.
> -- 
> "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] indexing

2007-02-01 Thread Dimitris Rizopoulos
one way is the following:

assignation$value[match(x, assignation$class)]


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "javier garcia-pintado" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, February 01, 2007 12:05 PM
Subject: [R] indexing


> Hello,
> In a nutshell, I've got a data.frame like this:
>
>> assignation <- 
>> data.frame(value=c(6.5,7.5,8.5,12.0),class=c(1,3,5,2))
>> assignation
>  value class
> 1   6.5 1
> 2   7.5 3
> 3   8.5 5
> 4  12.0 2
>>
>
> and a long vector of classes like this:
>
>> x <- c(1,1,2,7,6,5,4,3,2,2,2...)
>
> And would like to obtain  a vector of length = length(x), with the
> corresponding values extracted from assignation table. Like this:
>> x.value
> [1]  6.5  6.5 12.0   NA   NA  8.5   NA  7.5 12.0 12.0 12.0
>
> Could you help me with an elegant way to do this ?
> (I just can do it with looping for each class in the assignation 
> table,
> what a think is not perfect in R's sense)
>
> Wishes,
> Javier
> -- 
>
> Javier García-Pintado
> Institute of Earth Sciences Jaume Almera (CSIC)
> Lluis Sole Sabaris s/n, 08028 Barcelona
> Phone: +34 934095410
> Fax:   +34 934110012
> e-mail:[EMAIL PROTECTED]
>
>





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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Canging the type of point points sizein plots..

2007-01-27 Thread Dimitris Rizopoulos
try this

x1 <- rnorm(10); y1 <- rnorm(10)
x2 <- rnorm(10); y2 <- rnorm(10)
x3 <- rnorm(10); y3 <- rnorm(10)
#
plot(range(x1, x2, x3), range(y1, y2, y3), type = "n")
points(x1, y1, pch = 1, cex = 1, col = 1)
points(x2, y2, pch = 2, cex = 2, col = 2)
points(x3, y3, pch = 3, cex = 3, col = 3)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting vinod gullu <[EMAIL PROTECTED]>:

> I want to plot variation of more than one variable in
> single plot with different point types and points
> sizes . Can someone help me to do that,
>
> Thanks in advance.
> vinod
>
>
>
> 
> Now that's room service!  Choose from over 150,000 hotels
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Replace missing values in lapply

2007-01-24 Thread Dimitris Rizopoulos
you need to return x in the function within lapply(), e.g., something 
like

lapply(TP, function(x) { x[is.na(x)] <- 0; x })


I hope it works.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm



- Original Message - 
From: "Doran, Harold" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, January 24, 2007 4:40 PM
Subject: [R] Replace missing values in lapply


>I have some matrices stored as elements in a list that I am working
> with. On example is provided below as TP[[18]]
>
>> TP[[18]]
>  level2
> level1  1  2  3  4
> 1 79  0  0  0
> 2  0  0  0  0
> 3  0  0  0  0
> 4  0  0  0  0
>
> Now, using prop.table on this gives
>
>> prop.table(TP[[18]],1)
>  level2
> level1   1   2   3   4
> 1   1   0   0   0
> 2
> 3
> 4
>
> It is important for the zero's to retain their position as this 
> matrix
> will subsequently be used in some matrix multiplication and hence, 
> must
> be of dimension 4 by 4 so that is it conformable for multiplcation 
> with
> another matrix.
>
> In looking at the structure of the object resulting from prop.table 
> I
> see NaNs, and so I can do this
>
>> rr <- TP[[18]]
>> rr[is.na(rr)] <- 0
>> rr
>  level2
> level1  1  2  3  4
> 1 79  0  0  0
> 2  0  0  0  0
> 3  0  0  0  0
> 4  0  0  0  0
>
> This is exactly what I want for each matrix. But, I have multiple
> matrices stored within the list that need to be changed and so I am
> trying to resolve this via lapply, but something is awry (namely the
> user), but I could use a little help.
>
> I was thinking the following function should work, but it doesn't. 
> It
> reduces each matrix within the list to a 0.
>
> PP <- lapply(TP, function(x) x[is.na(x)] <- 0)
>
> Am I missing something obvious?
>
> Harold
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Conversion of column matrix into a vector without duplicates

2007-01-24 Thread Dimitris Rizopoulos
you need: unique(A[, 2])


Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Shubha Vishwanath Karanth" <[EMAIL PROTECTED]>
To: 
Sent: Wednesday, January 24, 2007 2:12 PM
Subject: [R] Conversion of column matrix into a vector without 
duplicates


> Hi R,
>
>
>
> I have a matrix A,
>
>
>
> A=
>
>  [,1] [,2]
>
> [1,]  a u
>
> [2,]  b v
>
> [3,]  c x
>
> [4,]  d x
>
> [5,]  e x
>
>
>
> I want to put the 2nd column of this matrix in a vector without
> duplicates. i.e., my vector v should be (u, v, x), whose length is 
> 3.
>
>
>
> Can anybody help me on this?
>
>
>
> Thanks in advance
>
> Shubha.
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


Re: [R] Matrix operations in a list

2007-01-23 Thread Dimitris Rizopoulos
you need the 'SIMPLIFY' argument of mapply(), i.e.,

mapply("%*%", a, b, SIMPLIFY = FALSE)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm

- Original Message - 
From: "Doran, Harold" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, January 23, 2007 4:21 PM
Subject: [R] Matrix operations in a list


>I have matrices stored within a list like something as follows:
>
> a <- list(matrix(rnorm(50), ncol=5), matrix(rnorm(50), ncol=5))
> b <- list(matrix(rnorm(50), nrow=5), matrix(rnorm(50), nrow=5))
>
> I don't recall how to perform matrix multiplication on each list 
> element
> such that the result is a new list
>
> result <- list(a[[1]]%*%b[[1]], a[[2]]%*%b[[2]])
>
> I think I'm close with mapply(), but I'm doing something silly
>
> mapply('%*%', a,b)
>
> Thanks.
> Harold
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Vector to Matrix transformation

2007-01-23 Thread Dimitris Rizopoulos
check the help page for ?matrix(); you probably want either

matrix(V1, nrow = 5)

or

matrix(V1, nrow = 5, byrow = TRUE)


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Shubha Vishwanath Karanth" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, January 23, 2007 3:10 PM
Subject: [R] Vector to Matrix transformation


> Hi R,
>
>
>
> I have a vector V1 of unknown length, say n. I need to convert this 
> into
> a matrix C of row size=5, and accordingly the column should be 
> updated.
> I tried with:
>
>
>
> C=as.matrix(V1,5,n/5)
>
>
>
> But it is not working...Could somebody help me on this?
>
>
>
> Thanks in advance...
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Integration + Normal Distribution + Directory Browsing Processing Questions

2007-01-22 Thread Dimitris Rizopoulos
the reason is that is more natural to use pnorm(), which also should a 
more efficient approximation of the Normal integral than intgrate(), 
you may even use

diff(pnorm(0:1, mean = 0.5, sd = 1.2))

however, the point I meant to make was to use the '...' argument that 
can found in many R functions.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Nils Hoeller" <[EMAIL PROTECTED]>
To: "Matthias Kohl" <[EMAIL PROTECTED]>
Cc: "Dimitris Rizopoulos" <[EMAIL PROTECTED]>; 

Sent: Monday, January 22, 2007 8:49 AM
Subject: Re: [R] Integration + Normal Distribution + Directory 
Browsing Processing Questions


> Thank you,
>
> both work fine. Why is pnorm to prefer?
>
> Nils
>
>
> Matthias Kohl schrieb:
>> Hi,
>>
>> why don't you use pnorm?
>> E.g.,
>>
>> pnorm(1, mean = 0.1, sd = 1.2) - pnorm(0, mean = 0.1, sd = 1.2)
>>
>> Matthias
>>
>> - original message 
>>
>> Subject: Re: [R] Integration + Normal Distribution + Directory 
>> Browsing Processing Questions
>> Sent: Sun, 21 Jan 2007
>> From: Dimitris Rizopoulos<[EMAIL PROTECTED]>
>>
>>
>>> you can use the `...' argument of integrate, e.g.,
>>>
>>> integrate(dnorm, 0, 1)
>>> integrate(dnorm, 0, 1, mean = 0.1)
>>> integrate(dnorm, 0, 1, mean = 0.1, sd = 1.2)
>>>
>>> look at ?integrate for more info.
>>>
>>> I hope it helps.
>>>
>>> Best,
>>> Dimitris
>>>
>>> 
>>> Dimitris Rizopoulos
>>> Ph.D. Student
>>> Biostatistical Centre
>>> School of Public Health
>>> Catholic University of Leuven
>>>
>>> Address: Kapucijnenvoer 35, Leuven, Belgium
>>> Tel: +32/(0)16/336899
>>> Fax: +32/(0)16/337015
>>> Web: http://med.kuleuven.be/biostat/
>>>   http://www.student.kuleuven.be/~m0390867/dimitris.htm
>>>
>>>
>>> Quoting Nils Hoeller <[EMAIL PROTECTED]>:
>>>
>>>
>>>> Hi everyone,
>>>>
>>>> I am new to R, but it's really great and helped me a lot!
>>>>
>>>> But now I have 2 questions. It would be great, if someone can 
>>>> help me:
>>>>
>>>> 1. I want to integrate a normal distribution, given a median and 
>>>> sd.
>>>> The integrate function works great BUT the first argument has to 
>>>> be a
>>>> function
>>>>
>>>> so I do integrate(dnorm,0,1) and it works with standard m. and 
>>>> sd.
>>>>
>>>> But I have the m and sd given.
>>>>
>>>> So for fixed m and sd I work around with a new function mynorm
>>>>
>>>> mynorm <- function(n) {
>>>> ret <- dnorm(n,0.6,0.15)
>>>> ret
>>>> }
>>>>
>>>> for example.
>>>>
>>>> BUT what can I do for dynamic m and sd?
>>>> I want something like integrate(dnorm(,0.6,0.15),0,1), with the 
>>>> first
>>>> dnorm parameter open for the
>>>> integration but fixed m and sd.
>>>>
>>>> I hope you can help me.
>>>>
>>>> 2. I am working with textfiles with rows of measure data.
>>>> read.table("file") works fine.
>>>>
>>>> Now I want R to read.table all files within a given directory and
>>>> process them one by the other.
>>>>
>>>> for(all files in dir xy) {
>>>> x <- read.table(nextfile)
>>>> process x
>>>> }
>>>>
>>>> Is that possible with R? I hope so. Can anyone give me a link to
>>>>
>>> examples.
>>>
>>>> Thanks for your help
>>>>
>>>> Nils
>>>>
>>>> __
>>>> R-help@stat.math.ethz.ch mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>>
>>> http://www.R-project.org/posting-guide.html
>>>
>>>> and provide commented, minimal, self-contained, reproducible 
>>>> code.
>>>>
>>>>
>>>>
>>>
>>> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>> --- original message end 
>>
>>
>> --
>> Dr. rer. nat. Matthias Kohl
>> [EMAIL PROTECTED]
>> www.stamats.de
>>
>>
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Integration + Normal Distribution + Directory Browsing Processing Questions

2007-01-21 Thread Dimitris Rizopoulos
you can use the `...' argument of integrate, e.g.,

integrate(dnorm, 0, 1)
integrate(dnorm, 0, 1, mean = 0.1)
integrate(dnorm, 0, 1, mean = 0.1, sd = 1.2)

look at ?integrate for more info.

I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
  http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Nils Hoeller <[EMAIL PROTECTED]>:

> Hi everyone,
>
> I am new to R, but it's really great and helped me a lot!
>
> But now I have 2 questions. It would be great, if someone can help me:
>
> 1. I want to integrate a normal distribution, given a median and sd.
> The integrate function works great BUT the first argument has to be a
> function
>
> so I do integrate(dnorm,0,1) and it works with standard m. and sd.
>
> But I have the m and sd given.
>
> So for fixed m and sd I work around with a new function mynorm
>
> mynorm <- function(n) {
> ret <- dnorm(n,0.6,0.15)
> ret
> }
>
> for example.
>
> BUT what can I do for dynamic m and sd?
> I want something like integrate(dnorm(,0.6,0.15),0,1), with the first
> dnorm parameter open for the
> integration but fixed m and sd.
>
> I hope you can help me.
>
> 2. I am working with textfiles with rows of measure data.
> read.table("file") works fine.
>
> Now I want R to read.table all files within a given directory and
> process them one by the other.
>
> for(all files in dir xy) {
> x <- read.table(nextfile)
> process x
> }
>
> Is that possible with R? I hope so. Can anyone give me a link to examples.
>
> Thanks for your help
>
> Nils
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

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


  1   2   3   4   5   6   >