Re: [R] question about poisson regression
On Tue, 14 May 2013, meng wrote: Many thanks. Another question: model- glm(count ~ drug*result, family = poisson) anova(model,test=Chisq) Df Deviance Resid. Df Resid. Dev Pr(Chi) NULL 3 47.522 drug 1 0.032 2 47.491 0.85858 result 1 41.187 1 6.304 1.383e-10 *** drug:result 1 6.304 0 0.000 0.01205 * T! he pvalue of drug is 0.85858,which indicates that the total count of drug1 and drug2 are not significantly different at 0.05 level. But: summary(model) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.0794 0.3536 5.882 4.06e-09 *** drug2 0.9163 0.4183 2.190 0.0285 * result2 1.9095 0.3788 5.041 4.64e-07 *** drug2:result2 -1.1211 0.4650 -2.411 0.0159 * The pvalue of drug2 is 0.0285 * ,which indicates that the total count of drug2 is significantly different from drug1 at 0.05 level,which contradict to the result of anova. Can you give me some help about that ? The anova tests the main effect of drug (without any other variable in the model) which is non-significant (62 vs. 64 observations). The summary gives the drug2 effect which pertains to the reference group (i.e., result = 1) and this is significant (8 vs. 20 observations). However, either result is probably not interesting. I guess the interaction (and possibly the result main effect) is the quantity of interest. Z Many thanks. Best At 2013-05-13 18:56:01,Achim Zeileis achim.zeil...@uibk.ac.at wrote: On Mon, 13 May 2013, meng wrote: Hi all: I have a question about poisson regression. My data: drug result count 1 1 8 1 254 2 1 20 2 2 44 My model: model- glm(count ~ drug*result, family = poisson) My result: summary(model) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.0794 0.3536 5.882 4.06e-09 *** drug2 0.9163 0.4183 2.190 0.0285 * result2 1.9095 0.3788 5.041 4.64e-07 *** drug2:result2 -1.1211 0.4650 -2.411 0.0159 * Calculation of coefficients: Intercept: drug=1 and result=1,the corresponding count is 8.So log(8) is 2.079442 which is Intercept. My question: How is drug2 calculated? log(64)-log(62) or something like that(indicates the difference between drug2 and drug1) ? I've searched and tried many times for all possible solutions,but the result is not 0.9163.So,how is drug2 calculated ? It's the drug2 effect (on a log-scale) for result=1, i.e., log(20) - log(8). The four coefficients are: R y - c(8, 20, 54, 44) R c(log(y[1]), log(y[2]) - log(y[1]), log(y[3]) - log(y[1]), +(log(y[4]) - log(y[3])) - (log(y[2]) - log(y[1]))) [1] 2.0794415 0.9162907 1.9095425 -1.1210851 Many thanks! Best [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.h tml and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] empirical and GPD time series simulation
Hi, Does anyone know how to simulate a long time series (say 1000 daily series) or generally a series, with inverse empirical distribution and generalized pareto distribution (meaning to say the time series has a marginal distribution of empirical and GPD distribution.)? Does anybody know if there is a package in R that do this thing? Many thanks B [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question about poisson regression
Many thanks. Another question: model- glm(count ~ drug*result, family = poisson) anova(model,test=Chisq) Df Deviance Resid. Df Resid. Dev Pr(Chi) NULL3 47.522 drug 10.032 2 47.491 0.85858 result 1 41.187 1 6.304 1.383e-10 *** drug:result 16.304 0 0.000 0.01205 * The pvalue of drug is 0.85858,which indicates that the total count of drug1 and drug2 are not significantly different at 0.05 level. But: summary(model) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.0794 0.3536 5.882 4.06e-09 *** drug2 0.9163 0.4183 2.190 0.0285 * result2 1.9095 0.3788 5.041 4.64e-07 *** drug2:result2 -1.1211 0.4650 -2.411 0.0159 * The pvalue of drug2 is 0.0285 * ,which indicates that the total count of drug2 is significantly different from drug1 at 0.05 level,which contradict to the result of anova. Can you give me some help about that ? Many thanks. Best At 2013-05-13 18:56:01,Achim Zeileis achim.zeil...@uibk.ac.at wrote: On Mon, 13 May 2013, meng wrote: Hi all: I have a question about poisson regression. My data: drug result count 1 1 8 1 254 2 1 20 2 2 44 My model: model- glm(count ~ drug*result, family = poisson) My result: summary(model) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.0794 0.3536 5.882 4.06e-09 *** drug2 0.9163 0.4183 2.190 0.0285 * result2 1.9095 0.3788 5.041 4.64e-07 *** drug2:result2 -1.1211 0.4650 -2.411 0.0159 * Calculation of coefficients: Intercept: drug=1 and result=1,the corresponding count is 8.So log(8) is 2.079442 which is Intercept. My question: How is drug2 calculated? log(64)-log(62) or something like that(indicates the difference between drug2 and drug1) ? I've searched and tried many times for all possible solutions,but the result is not 0.9163.So,how is drug2 calculated ? It's the drug2 effect (on a log-scale) for result=1, i.e., log(20) - log(8). The four coefficients are: R y - c(8, 20, 54, 44) R c(log(y[1]), log(y[2]) - log(y[1]), log(y[3]) - log(y[1]), +(log(y[4]) - log(y[3])) - (log(y[2]) - log(y[1]))) [1] 2.0794415 0.9162907 1.9095425 -1.1210851 Many thanks! Best [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with R websocket package
Hello to everybody, Â I seem to be in struggle with the websockets in R. I wanted to download the streaming data from the BitCoin exchange MtGox directly to R, but R cannot establish the connection. The websocket specs are defined as: * Host: websocket.mtgox.com or socketio.mtgox.com * Port: 80 or 443 ( ssl ) * Namespace: /mtgox (Including beginning slash) url for more details: https://en.bitcoin.it/wiki/MtGox/API/Streaming (https://en.bitcoin.it/wiki/MtGox/API/Streaming) and my code is: codespan class='kwd'require/spanspan class='pun'(/spanspan class='pln'websockets/spanspan class='pun')/spanspan class='pln' con /spanspan class='pun'=/spanspan class='pln' websocket/spanspan class='pun'(/spanspan class='str'https://socketio.mtgox.com/mtgox;/spanspan class='pun',/spanspan class='pln'port/spanspan class='pun'=/spanspan class='lit'443/spanspan class='pun')/span/code and I always end up with an error: codespan class='pun'/spanspan class='pln' con /spanspan class='pun'=/spanspan class='pln' websocket/spanspan class='pun'(/spanspan class='str'https://socketio.mtgox.com/mtgox;/spanspan class='pun',/spanspan class='pln'port/spanspan class='pun'=/spanspan class='lit'443/spanspan class='pun')/spanspan class='pln' /spanspan class='typ'Error/spanspan class='pln' /spanspan class='kwd'in/spanspan class='pln' websocket/spanspan class='pun'(/spanspan class='str'https://socketio.mtgox.com/mtgox;/spanspan class='pun',/spanspan class='pln' port /spanspan class='pun'=/spanspan class='pln' /spanspan class='lit'443/spanspan class='pun')/spanspan class='pln' /spanspan class='pun':/spanspan class='pln' /spanspan class='typ'Connection/spanspan class='pln' error/span/code Does anyone have an idea what is wrong? I was informed that MtGox does not use the proper websocket protocol but something called Socket-io. Is it the reason why it doesn't work? If so, is there any other way to handle socket-io in R? I searched all websockets packages but did not find any. Â Many thanks for help. Stepan = [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dataframe and conditions
I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b==TRUE I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-and-conditions-tp4667012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe and conditions
Hello, Try the following. X$a[X$b] - X$c[X$b] Hope this helps, Rui Barradas Em 14-05-2013 09:06, fgrelier escreveu: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b==TRUE I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-and-conditions-tp4667012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe and conditions
Hello, One approach is using ifelse: X - data.frame(a=c(1,1,1,1,1,1), b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2)) X a b c 1 1 TRUE 2 2 1 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 1 TRUE 2 X - within(X, a - ifelse(b==TRUE, c, a)) X a b c 1 2 TRUE 2 2 2 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 2 TRUE 2 Hope this helps, Pascal On 05/14/2013 05:06 PM, fgrelier wrote: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b==TRUE I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-and-conditions-tp4667012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Unexpected behavior of apply when FUN=sample
Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. Kind regards, Luca Nanetti -- __ Luca Nanetti, MSc, MRI University Medical Center Groningen Neuroimaging Center Groningen Groningen, The Netherlands Tel: +31 50 363 4733 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to capture the expression corresponding to the i param in the [ function
Dear David, First, I would like to say thank you for your very soon reply. Second, I want to clarify the question because it seems to not carrying exactly what I want to ask. Let take an example on R data.frame: V1 - 1 df2 - df[V1== 1,] # df is a data.frame, this command is correct, right? The evaluation steps for the above command are: 1. R evaluate V1 1 to get TRUE 2. The command becomes df2 - df[TRUE,] which copies all rows of df to df2 What I want is to capture the V1 1 expression instead of letting R do the evaluation in case of the custom [ function. Assume my class is mydf, the S4 function should be: setMethod([, signature(x=mydf), function(x,i,j,...,drop=TRUE) { e - substitute(i) // do parsing and custom-evaluation tasks }) Currently, i is always a vector of type character, numeric or logic due to R evaluation. I am a newbie to R, so please tolerate my mistakes or misunderstanding. Thanks! Nhan Vu On Tue, May 14, 2013 at 12:14 PM, David Winsemius dwinsem...@comcast.netwrote: On May 13, 2013, at 6:38 PM, Nhan Vu Lam Chi wrote: Hi everyone, I currently work on a S4 class that has the [ function. I want to capture the unevaluated expression corresponding to the i param using substitute() function and do a non-standard evaluation. However R automatically evaluates the expression and give me its value. For example: Given mydf[mydf$V1 1,] with mydf is an object of my custom S4 dataframe class and V1 is one of its columns, I want to get the unevaluated expression mydf$V1 1. My questions are: 1. Is it possible to do that in R? 2. If yes, how to do? Doesn't this cry out for the S4 class definition of [ to be answerable?. Because [ is generic, it could have almost any definition at the whim of the package author. My R version and OS info are: R version 2.15.3 (2013-03-01) -- Security Blanket Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) This is the first time I post to the mailing list, so please forgive any mistakes and/or advise me if possible. Regards, Nhan Vu [[alternative HTML version deleted]] You are forgiven, but this once, for posting in HTML. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
On 13-05-14 4:52 AM, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. It's is already very explicit: If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n 1. In your first case, sample is applied to columns, and returns length 7 results, so the shape of the final result is c(7, 5). In the second case it is applied to rows, and returns length 5 results, so the shape is c(5, 7). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
On Tue, 14 May 2013, Luca Nanetti luca.nane...@gmail.com writes: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. As you said yourself, this behaviour is documented: If each call to ‘FUN’ returns a vector of length ‘n’, then ‘apply’ returns an array of dimension ‘c(n, dim(X)[MARGIN])’ [...] And it has nothing to do with 'sample'. Try: apply(test, 1, function(x) x) apply(test, 2, function(x) x) The result is only counterintuitive (or inconvenient, perhaps) in the special case in which apply is supposed to return an array that has the same dimension as its input. More generally, you will do something like apply(test, 1, median) apply(test, 1, function(x) list(sum = sum(x), values = x)) and in such cases, apply does not return an array. -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
Hello, The problem is that apply returns the results vector by vector and in R vectors are column vectors. This is not exclusive of apply with sample as the function to be called, but of apply in general. Try, for instance apply(test, 1, identity) # transposes the array The rows are returned as column vectors. And you should expect this behavior from apply with MARGIN = 1. And this is in fact documented, in the Value section of ?apply: Value If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n 1. The length of the returned vector is the number of rows and the number of columns is the dim corresponding to MARGIN... Hope this helps, Rui Barradas Em 14-05-2013 09:52, Luca Nanetti escreveu: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. Kind regards, Luca Nanetti __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
On 14-May-2013 09:46:32 Duncan Murdoch wrote: On 13-05-14 4:52 AM, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. It's is already very explicit: If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n 1. In your first case, sample is applied to columns, and returns length 7 results, so the shape of the final result is c(7, 5). In the second case it is applied to rows, and returns length 5 results, so the shape is c(5, 7). Duncan Murdoch And the (quite simple) practical implication of what Duncan points out is: test - array(1:35, dim=c(7, 5)) test # [,1] [,2] [,3] [,4] [,5] # [1,]18 15 22 29 # [2,]29 16 23 30 # [3,]3 10 17 24 31 # [4,]4 11 18 25 32 # [5,]5 12 19 26 33 # [6,]6 13 20 27 34 # [7,]7 14 21 28 35 # To permute the rows: t(apply(t(test), 2, sample)) # [,1] [,2] [,3] [,4] [,5] # [1,] 22 298 151 # [2,] 30 16 2329 # [3,] 10 31 243 17 # [4,] 114 25 32 18 # [5,] 265 12 33 19 # [6,] 27 34 20 136 # [7,] 35 28 147 21 which looks right! Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 14-May-2013 Time: 11:07:46 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
On Tue, May 14, 2013 at 4:52 AM, Luca Nanetti luca.nane...@gmail.com wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. aaply in the plyr package works in the way you expected. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Possible bug in 'data.table'
Dear R users, I may have found a bug in the function 'data.table'. I have a similar question as the one in this post: http://stackoverflow.com/questions/3367190/aggregate-and-weighted-mean-in-r I have a dataset with assets, quantity traded, date and time. I would like to calculate the value weighted average time of trades, by date of trade. The variables are as follows: Classes ‘data.table’ and 'data.frame': 307787 obs. of 12 variables: $ CODE: int 1 2 3 4 4 5 3 2 2 1 $ DATE : int 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 ... $ TIME : chr 09:14:14 09:14:33 09:26:19 09:40:45 ... $ PRICE: num 105.2 105.2 96.8 96.9 96.8 ... $ QTY : int 500 500 500 1000 500 500 1000 300 1000 500 ... $ DATE2: Date, format: 2007-01-02 2007-01-02 2007-01-02 2007-01-02 ... $ TIME2: chr 09:14:14 09:14:33 09:26:19 09:40:45 ... $ TIME3: POSIXlt, format: 2013-05-13 09:14:14 2013-05-13 09:14:33 2013-05-13 09:26:19 2013-05-13 09:40:45 ... - attr(*, .internal.selfref)=externalptr If I run the command temp[,list(weighted.mean(PRICE,QTY)),by=DATE2] I get DATE2V1 1: 2007-01-02 100.67024 2: 2007-01-03 99.89599 3: 2007-01-04 100.54347 4: 2007-01-05 100.82472 5: 2007-01-08 99.39865 --- 1524: 2012-12-19 103.73392 1525: 2012-12-20 103.77344 1526: 2012-12-21 102.89063 1527: 2012-12-27 101.53089 1528: 2012-12-28 103.35999 While I run the command temp[,list(weighted.mean(TIME3,QTY)),by=DATE2] R crashes. This behavior occurs in both R Studio and R GUI, regardless of the version (2.14, 2.15, 3.0). Is it really a bug or am I doing something wrong? -- View this message in context: http://r.789695.n4.nabble.com/Possible-bug-in-data-table-tp4667025.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
t(apply(test,1,sample)) will also do. As the OP noted, the results are simply transposed. So if an operation is to be applied to rows, yielding modified rows, simply transpose the results. Cheers, Tsjerk On Tue, May 14, 2013 at 12:07 PM, Ted Harding ted.hard...@wlandres.netwrote: On 14-May-2013 09:46:32 Duncan Murdoch wrote: On 13-05-14 4:52 AM, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. It's is already very explicit: If each call to FUN returns a vector of length n, then apply returns an array of dimension c(n, dim(X)[MARGIN]) if n 1. In your first case, sample is applied to columns, and returns length 7 results, so the shape of the final result is c(7, 5). In the second case it is applied to rows, and returns length 5 results, so the shape is c(5, 7). Duncan Murdoch And the (quite simple) practical implication of what Duncan points out is: test - array(1:35, dim=c(7, 5)) test # [,1] [,2] [,3] [,4] [,5] # [1,]18 15 22 29 # [2,]29 16 23 30 # [3,]3 10 17 24 31 # [4,]4 11 18 25 32 # [5,]5 12 19 26 33 # [6,]6 13 20 27 34 # [7,]7 14 21 28 35 # To permute the rows: t(apply(t(test), 2, sample)) # [,1] [,2] [,3] [,4] [,5] # [1,] 22 298 151 # [2,] 30 16 2329 # [3,] 10 31 243 17 # [4,] 114 25 32 18 # [5,] 265 12 33 19 # [6,] 27 34 20 136 # [7,] 35 28 147 21 which looks right! Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 14-May-2013 Time: 11:07:46 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Tsjerk A. Wassenaar, Ph.D. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] points overlay axis
Hi, I'm trying to do quite a simple task, but I'm stuck. I've set xaxs = 'i' as I want the origin to be (0,0), but unfortunately I have points that are sat on the axis. R draws the axis over the points, which hides the points somewhat and looks unsightly. Is there any way of getting a point to be drawn over the axis? Thanks, Jon Phillips [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] points overlay axis
Probably but since we don't know what you are doing, it is very hard to give any advice. Please read this for a start https://github.com/hadley/devtools/wiki/Reproducibility and give us a clear statement of the problem Thanks John Kane Kingston ON Canada -Original Message- From: 994p...@gmail.com Sent: Tue, 14 May 2013 13:34:35 +0100 To: r-help@r-project.org Subject: [R] points overlay axis Hi, I'm trying to do quite a simple task, but I'm stuck. I've set xaxs = 'i' as I want the origin to be (0,0), but unfortunately I have points that are sat on the axis. R draws the axis over the points, which hides the points somewhat and looks unsightly. Is there any way of getting a point to be drawn over the axis? Thanks, Jon Phillips [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with R websocket package
Hello to everybody, I'm repeating my post as the previous one was posted in HTML - sorry guys! I seem to be in struggle with the websockets in R. I wanted to download the streaming data from the BitCoin exchange MtGox directly to R, but R cannot establish the connection. The websocket specs are defined as: Host: websocket.mtgox.com or socketio.mtgox.com Port: 80 or 443 ( ssl ) Namespace:/mtgox (Including beginning slash) url for more details: https://en.bitcoin.it/wiki/MtGox/API/Streaming and my code is: require(websockets) con = websocket(https://socketio.mtgox.com/mtgox,port=443) and I always end up with an error: con = websocket(https://socketio.mtgox.com/mtgox,port=443) Error in websocket(https://socketio.mtgox.com/mtgox;, port = 443) : Connection error Does anyone have an idea what is wrong? I was informed that MtGox does not use the proper websocket protocol but something called Socket-io. Is it the reason why it doesn't work? If so, is there any other way to handle socket-io in R? I searched all websockets packages but did not find any. Many thanks for help. Stepan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 column from the data.frame?
Hi, Try: set.seed(24) dat1- as.data.frame(matrix(sample(1:60,15*5,replace=TRUE),ncol=15)) colnames(dat1)- paste0(a,c(3,1,5,7,2,8,11,14:15,10,9,6,12:13,4)) subDat1-dat1[colnames(dat1)[as.numeric(gsub([A-Za-z],,colnames(dat1)))=10]] subDat1 # a3 a1 a5 a7 a2 a8 a10 a9 a6 a4 #1 18 56 37 55 6 42 5 28 60 9 #2 14 17 23 12 34 5 24 52 28 13 #3 43 46 41 3 44 36 22 28 18 1 #4 32 49 41 31 9 38 16 43 11 60 #5 40 16 20 9 14 3 21 33 9 39 A.K. Hi, I have one data set with 15 variable like a3, a1, a5, a7,a2, a8, a11, a14, a15, a10, a9, a6, a12, a13, a4. From this variable i want to select variables from a1:a10. Please helpe to to get the result.. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] apcluster webinar: Thursday, June 13, 2013, 7:00pm CEST
Dear colleagues, This is to inform you that I will be giving a webinar on the apcluster package on Thursday, June 13, 2013, 7:00pm CEST (10:00am PDT). The outline of the one-hour webinar is as follows: - Introduction to affinity propagation (AP) clustering - The apcluster package, its algorithms, and visualization tools - Live apcluster demonstration - Question and Answer period To register for the webinar, please visit the following URL: https://www3.gotomeeting.com/register/503109182 The webinar is kindly brought to you by the Orange County R User Group, and will be moderated by its president, Ray DiGiacomo, Jr. We are aware that the time may be inconvenient for users from the Asia-Pacific region. If there is demand (please let us know!), we are willing to organize a second webinar at a time that is more suitable for Asian-Pacific users. Best regards, Ulrich Bodenhofer *Dr. Ulrich Bodenhofer* Associate Professor Institute of Bioinformatics *Johannes Kepler University* Altenberger Str. 69 4040 Linz, Austria Tel. +43 732 2468 4526 Fax +43 732 2468 4539 bodenho...@bioinf.jku.at http://www.bioinf.jku.at/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] need help for Imbalanced classification problems!!!
Hi all, I am facing the imbalanced classification problems. That means I have a dataset, in which the ratio of majority data to minority data is 100:1 (or more). In addition, the independent variables are many and this is a binary classification questions. The model I built give poor predictive power for minor data, but for the majority data the predictivity seems to overfitting. Could you give me a suggestions to solve the imbalanced classification problems? Thanks in advance! Kevin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] points overlay axis
Try this set.seed(42) dat - matrix(c(runif(48), 0, 0), 25, 2, byrow=TRUE) # Complete plot symbol on axes, but axis on top plot(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE) # Complete plot symbol on axes with symbol on top plot(dat, xaxs=i, yaxs=i, type=n) points(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE) David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Tuesday, May 14, 2013 7:47 AM To: Jonathan Phillips; r-help@r-project.org Subject: Re: [R] points overlay axis Probably but since we don't know what you are doing, it is very hard to give any advice. Please read this for a start https://github.com/hadley/devtools/wiki/Reproducibility and give us a clear statement of the problem Thanks John Kane Kingston ON Canada -Original Message- From: 994p...@gmail.com Sent: Tue, 14 May 2013 13:34:35 +0100 To: r-help@r-project.org Subject: [R] points overlay axis Hi, I'm trying to do quite a simple task, but I'm stuck. I've set xaxs = 'i' as I want the origin to be (0,0), but unfortunately I have points that are sat on the axis. R draws the axis over the points, which hides the points somewhat and looks unsightly. Is there any way of getting a point to be drawn over the axis? Thanks, Jon Phillips [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] points overlay axis
Let's try again after restraining Outlook's desire to use html. set.seed(42) dat - matrix(c(runif(48), 0, 0), 25, 2, byrow=TRUE) # Complete plot symbol on axes, but axis on top plot(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE) # Complete plot symbol on axes with symbol on top plot(dat, xaxs=i, yaxs=i, type=n) points(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE) David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Tuesday, May 14, 2013 7:47 AM To: Jonathan Phillips; r-help@r-project.org Subject: Re: [R] points overlay axis Probably but since we don't know what you are doing, it is very hard to give any advice. Please read this for a start https://github.com/hadley/devtools/wiki/Reproducibility and give us a clear statement of the problem Thanks John Kane Kingston ON Canada -Original Message- From: 994p...@gmail.com Sent: Tue, 14 May 2013 13:34:35 +0100 To: r-help@r-project.org Subject: [R] points overlay axis Hi, I'm trying to do quite a simple task, but I'm stuck. I've set xaxs = 'i' as I want the origin to be (0,0), but unfortunately I have points that are sat on the axis. R draws the axis over the points, which hides the points somewhat and looks unsightly. Is there any way of getting a point to be drawn over the axis? Thanks, Jon Phillips [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Possible bug in 'data.table'
Manta mantino84 at libero.it writes: Dear R users, I may have found a bug in the function 'data.table'. I have a similar question as the one in this post: http://stackoverflow.com/questions/3367190/ aggregate-and-weighted-mean-in-r [snip] While I run the command temp[,list(weighted.mean(TIME3,QTY)),by=DATE2] R crashes. This behavior occurs in both R Studio and R GUI, regardless of the version (2.14, 2.15, 3.0). Is it really a bug or am I doing something wrong? If by crash you mean that the program actually terminates (i.e. not just an error), then this is by definition a bug in data.table -- there is a bug tracker at https://r-forge.r-project.org/tracker/?group_id=240 , or you could try contacting the package maintainer (help(package=data.table) or maintainer(data.table) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 to building R package with devtools
Can someone help what I need to do to make 'devtools' work? A quick asking around indicates that Rtools 3.0 should work fine for 2.15.3 maintenance. Thus, the issue is probably a purely formal bug in devtools's version comparison logic, and you need to pester its maintainer. Unless it has been fixed already, in which case you need to update devtools. I'm pretty sure it has been fixed already, otherwise please file a bug (with a copy of your sessionInfo()) at https://github.com/hadley/devtools/issues -- RStudio / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe and conditions
Thanks a lot Guys That works I appreciate your helps Best regards Frederic FREDERIC GRELIER DIRECTEUR DATA T +33 (0) 1 83 94 04 08 - P +33 (0) 6 70 50 01 05 - F +33 (0) 1 53 19 41 84 WWW.WEBORAMA.COM http://www.weborama.com/ - 15, RUE CLAVEL - 75019 PARIS -Message d'origine- De : arun [mailto:smartpink...@yahoo.com] Envoyé : mardi 14 mai 2013 15:19 À : Pascal Oettli Cc : R help; fgrelier Objet : Re: [R] Dataframe and conditions #this should also work within(X,a- ifelse(b,c,a)) # a b c #1 2 TRUE 2 #2 2 TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE 2 #6 2 TRUE 2 A.K. - Original Message - From: Pascal Oettli kri...@ymail.com To: fgrelier fgrel...@weborama.com Cc: r-help@r-project.org Sent: Tuesday, May 14, 2013 4:47 AM Subject: Re: [R] Dataframe and conditions Hello, One approach is using ifelse: X - data.frame(a=c(1,1,1,1,1,1), b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2)) X a b c 1 1 TRUE 2 2 1 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 1 TRUE 2 X - within(X, a - ifelse(b==TRUE, c, a)) X a b c 1 2 TRUE 2 2 2 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 2 TRUE 2 Hope this helps, Pascal On 05/14/2013 05:06 PM, fgrelier wrote: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b==TRUE I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-and-conditions-tp4667012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with constrained nlsList model
I have some longitudinal data I'm fitting with an asymptotic growth function constrained to the origin. Visual inspection of the dataset suggests this is reasonable! library(nlme) results - groupedData(y~Days | ID, data=results) m1 - nlsList(SSasympOrig, na.omit(results)) m1 Call: Model: y ~ SSasympOrig(Days, Asym, lrc) | ID Data: na.omit(results) Coefficients: Asym lrc 1765.259815 -5.048464 186 13.833871 -4.337267 300 16.007862 -4.783315 159 21.509863 -4.241172 144 103.505322 -7.040130 161 49.746946 -5.682995 170 50.964702 -5.739456 293 63.060652 -5.928408 142 49.851672 -4.707905 261 48.612882 -4.568154 184 63.633909 -5.361407 162 49.478622 -4.088146 202 714.579639 -9.128026 303 53.688201 -3.750039 275 63.298936 -4.757936 264 60.868979 -5.029757 199 64.776418 -5.163388 1368 107.784023 -6.478387 212 99.200012 -6.566332 204 67.462536 -4.994269 177 120.435299 -6.125227 92 125.594800 -6.699715 210 63.899406 -4.055854 268 68.053434 -4.037159 201 133.915623 -6.786009 255 78.692978 -4.262876 273 80.826720 -4.481234 249 90.353950 -4.188984 238 97.372830 -3.969175 248 84.202629 -3.894503 208 104.325471 -4.209675 258 265.856493 -5.741356 So this appears to work reasonably well. For theoretical reasons in this context I also want to look at an asymptotic growth function additionally constrained with asymptote a constant (=100), i.e. with only the rate-constant/half-life free. I'm not sure how to modify the built-in SSasympOrig function to achieve this however thought this would work: m2 - nlsList(y~100*(1-exp(-exp(lrc*Days))), start=list(lrc=-5), data=na.omit(results)) but this results in the error message Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates for every estimation I realise that constraining the asymptote will force large changes in the estimate of lrc (e.g. particularly in the first case ID == 176) but many of the free-floating estimates of Asym are of the order of ~ 100 so I'm not sure why the constrained nls model doesn't converge on at least some occasions? Am I doing something else wrong? Thanks Rob __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] where clauses - help
hello, I wrote a foreach loop containing where clauses. R indicates an error in the compilation of the where clause. Could you please tell me why not right? foreach (series. combine = c)%:% when (mydata [3] = u [1]) % Dopar% (mydata [5] / sum (mydata [5])) L 'error reported by R is: Error: unexpected '=' in foreach (series. Combine = c)%:% when (mydata [3] = many thanks in advance Martina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe and conditions
#this should also work within(X,a- ifelse(b,c,a)) # a b c #1 2 TRUE 2 #2 2 TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE 2 #6 2 TRUE 2 A.K. - Original Message - From: Pascal Oettli kri...@ymail.com To: fgrelier fgrel...@weborama.com Cc: r-help@r-project.org Sent: Tuesday, May 14, 2013 4:47 AM Subject: Re: [R] Dataframe and conditions Hello, One approach is using ifelse: X - data.frame(a=c(1,1,1,1,1,1), b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2)) X a b c 1 1 TRUE 2 2 1 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 1 TRUE 2 X - within(X, a - ifelse(b==TRUE, c, a)) X a b c 1 2 TRUE 2 2 2 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 2 TRUE 2 Hope this helps, Pascal On 05/14/2013 05:06 PM, fgrelier wrote: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b==TRUE I have tried to put in place a loop but as I have a lot of rows it is very very long to run. Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/Dataframe-and-conditions-tp4667012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where clauses - help
On May 14, 2013, at 17:06 , martinizza wrote: hello, I wrote a foreach loop containing where clauses. R indicates an error in the compilation of the where clause. Could you please tell me why not right? foreach (series. combine = c)%:% when (mydata [3] = u [1]) % Dopar% (mydata [5] / sum (mydata [5])) L 'error reported by R is: Error: unexpected '=' in foreach (series. Combine = c)%:% when (mydata [3] = This comes from a package, the package has a maintainer, the maintainer is associated with a commercial company... Anyways, offhand:The comparison operator is == . You likely also need %dopar% (case and spaces do matter). And remove a space and add a comma within the first parenthesis. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where clauses - help
On 14/05/2013 11:06 AM, martinizza wrote: hello, I wrote a foreach loop containing where clauses. R indicates an error in the compilation of the where clause. Could you please tell me why not right? foreach (series. combine = c)%:% when (mydata [3] = u [1]) % Dopar% (mydata [5] / sum (mydata [5])) L 'error reported by R is: Error: unexpected '=' in foreach (series. Combine = c)%:% when (mydata [3] = I don't know foreach, but it looks as though your = sign should be == to test for equality. The first part looks funny too: shouldn't that be a comma after series, rather than a period? Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] query re plot(confint(lmList...
Hi - My sample size is about 190, consequently the plot output (below) is quite squashed up and the id numbers down the L axis overlay each other and are not legible plot(confint(lmList(x ~ slope | id, data), pooled = TRUE), order = 1) Is it possible to either reduce the size of the id numbers down the L axis or spread the plots out over a couple of pages so the text is less squashed up? (- I need to retain the ordering). I've tried the usual plot function arguments (amongst other things) but alas to no avail. Thanks! M [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] query in plot(intervals....
Hi - I would like the plot ordered by intercept. Ordering is doable if the intervals function is substituted with the confint function and order=1 included. Is ordering doable with intervals function, please? Thanks! M results-lmList(x~slope|id,data) plot(intervals(results)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 3D plot
Dear all, I need to plot more than one surface in 3D using R. I tried with persp function, it produce only one surface. Could you please help me how can I do it? The X and Y axis are the same but I have Z1 and Z2. I want to have both results in one graph. Thanks Amir -- __ Amir Darehshoorzadeh | Computer Engineering Department PostDoc Fellow | University of Ottawa, Paradise LAb Email: adare...@uottawa.ca | 800 King Edward Ave Tel: - | ON K1N 6N5, Ottawa - CANADA http://personals.ac.upc.edu/amir __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing Order of Factor Levels in Mixed Model (nlme)
R Help - Why is that in the results below, changing the order of the factor (trialType2: levels - DD, SD, DS, SS) changes the estimates in the fixed effects tests? tmp.dat4$trialType2 - sort(tmp.dat4$trialType, decreasing = TRUE) mod2c - lme(proportion.down ~ trialType2, data = tmp.dat4, random = ~ 1 | subject, na.action = na.omit, method = ML) summary(mod2c) Linear mixed-effects model fit by maximum likelihood Data: tmp.dat4 AIC BIClogLik 27.92306 48.23003 -7.961531 Random effects: Formula: ~1 | subject (Intercept) Residual StdDev: 0.3800017 0.1530272 Fixed effects: proportion.down ~ trialType2 Value Std.Error DF t-value p-value (Intercept) 0.6788875 0.08613476 141 7.881690 0. trialType2DS 0.0287062 0.11267357 141 0.254773 0.7993 trialType2SD -0.0197194 0.12142018 141 -0.162406 0.8712 trialType2SS -0.0941918 0.12204707 141 -0.771766 0.4415 Correlation: (Intr) trT2DS trT2SD trialType2DS -0.658 trialType2SD -0.709 0.467 trialType2SS -0.706 0.464 0.571 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -3.67176824 -0.22090663 0.08677971 0.14331603 2.86301670 Number of Observations: 218 Number of Groups: 74 tmp.dat4$trialType2 - sort(tmp.dat4$trialType, decreasing = FALSE) mod2c - lme(proportion.down ~ trialType2, data = tmp.dat4, random = ~ 1 | subject, na.action = na.omit, method = ML) summary(mod2c) Linear mixed-effects model fit by maximum likelihood Data: tmp.dat4 AIC BIClogLik 27.92306 48.23003 -7.961531 Random effects: Formula: ~1 | subject (Intercept) Residual StdDev: 0.3800017 0.1530272 Fixed effects: proportion.down ~ trialType2 Value Std.Error DF t-value p-value (Intercept) 0.5846957 0.08646554 141 6.762181 0. trialType2DS 0.0744724 0.1123 141 0.660347 0.5101 trialType2SD 0.1228981 0.12175741 141 1.009368 0.3145 trialType2SS 0.0941918 0.12204707 141 0.771766 0.4415 Correlation: (Intr) trT2DS trT2SD trialType2DS -0.660 trialType2SD -0.710 0.469 trialType2SS -0.708 0.468 0.573 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -3.67176824 -0.22090663 0.08677971 0.14331603 2.86301670 Number of Observations: 218 Number of Groups: 74 -- *Edward H Patzelt | Research Assistant Psychology | University of Minnesota | Elliott Hall, 75 East River Road | Minneapolis, MN 55455 Email: patze...@umn.edu | Main: 612.626.0072 | Mobile: 651.315.3410 | Office: S355 ** * [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] query re plot(confint(lmList...
Please don't post in html. The list strips it out and we, now, have no idea of what you are doing. Have a look at https://github.com/hadley/devtools/wiki/Reproducibility for suggestions on how to ask a qustion here. Sample code and sample data (see ?dupt) are usually desirable. John Kane Kingston ON Canada -Original Message- From: mm...@hermes.cam.ac.uk Sent: Tue, 14 May 2013 16:54:36 +0100 To: r-help@r-project.org Subject: [R] query re plot(confint(lmList... Hi - My sample size is about 190, consequently the plot output (below) is quite squashed up and the id numbers down the L axis overlay each other and are not legible plot(confint(lmList(x ~ slope | id, data), pooled = TRUE), order = 1) Is it possible to either reduce the size of the id numbers down the L axis or spread the plots out over a couple of pages so the text is less squashed up? (- I need to retain the ordering). I've tried the usual plot function arguments (amongst other things) but alas to no avail. Thanks! M [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D plot
On 14/05/2013 1:10 PM, Amir wrote: Dear all, I need to plot more than one surface in 3D using R. I tried with persp function, it produce only one surface. Could you please help me how can I do it? The X and Y axis are the same but I have Z1 and Z2. I want to have both results in one graph. That's quite hard to do with persp because it needs to plot the segments in a certain order. You can do it in the rgl package using persp3d for the first surface, then persp3d( ..., add=TRUE) for the second. Note that persp3d and persp use slightly different conventions for how to specify colours; see ?persp3d for details. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] query re plot(confint(lmList...
On 14/05/2013 11:54 AM, Michelle Morters wrote: Hi - My sample size is about 190, consequently the plot output (below) is quite squashed up and the id numbers down the L axis overlay each other and are not legible plot(confint(lmList(x ~ slope | id, data), pooled = TRUE), order = 1) Is it possible to either reduce the size of the id numbers down the L axis or spread the plots out over a couple of pages so the text is less squashed up? (- I need to retain the ordering). I've tried the usual plot function arguments (amongst other things) but alas to no avail. You don't give a reproducible example or say what package lmList came from. However, if you want two plots, presumably you could use the subset() function to select out only some of the id values, and then do it again to get the rest. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] query re plot(confint(lmList...
Or better yet see ?dput, sorry. John Kane Kingston ON Canada -Original Message- From: jrkrid...@inbox.com Sent: Tue, 14 May 2013 09:20:59 -0800 To: mm...@hermes.cam.ac.uk, r-help@r-project.org Subject: Re: [R] query re plot(confint(lmList... Please don't post in html. The list strips it out and we, now, have no idea of what you are doing. Have a look at https://github.com/hadley/devtools/wiki/Reproducibility for suggestions on how to ask a qustion here. Sample code and sample data (see ?dupt) are usually desirable. John Kane Kingston ON Canada -Original Message- From: mm...@hermes.cam.ac.uk Sent: Tue, 14 May 2013 16:54:36 +0100 To: r-help@r-project.org Subject: [R] query re plot(confint(lmList... Hi - My sample size is about 190, consequently the plot output (below) is quite squashed up and the id numbers down the L axis overlay each other and are not legible plot(confint(lmList(x ~ slope | id, data), pooled = TRUE), order = 1) Is it possible to either reduce the size of the id numbers down the L axis or spread the plots out over a couple of pages so the text is less squashed up? (- I need to retain the ordering). I've tried the usual plot function arguments (amongst other things) but alas to no avail. Thanks! M [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] query in plot(intervals....
On Tue, May 14, 2013 at 10:05 AM, Michelle Morters mm...@hermes.cam.ac.ukwrote: Hi - I would like the plot ordered by intercept. One way will be to tweak the ?intervals.lmList object require(nlme) fm1 - intervals(lmList(distance ~ age | Subject, Orthodont)) fm2 - fm1[order(fm1[,2,1]),,] class(fm2) - class(fm1) plot(fm2) Next time please, *you* provide the reproducible example... Ordering is doable if the intervals function is substituted with the confint function and order=1 included. Is ordering doable with intervals function, please? Thanks! M results-lmList(x~slope|id,data) plot(intervals(results)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ?on-consequitve # of lags in VAR (package 'vars)?
My question has been answered elsewhere, but here is the answer: ?restrict On Mon, May 13, 2013 at 8:49 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I was wondering if it is at all possible (in vars or maybe outside of it?) to include non-consequite lags into the model, vor example lags 1 and 3. So far, it looks like when I set p = 3 under VAR, it includes all lags (1:3). Thank you very much! -- Dimitri Liakhovitski -- Dimitri Liakhovitski -- Dimitri Liakhovitski [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Specifying Correlation Structures in Linear Multivariate State Space Models
I am investigating various R packages that facilitate estimation of linear Gaussian multivariate state space models. I stumbled across the MARSS package (http://cran.r-project.org/web/packages/MARSS/index.html), which I believe is very well done, but am finding one missing feature that I cannot live without. I am trying to estimate a Gaussian multiuvatiate local level model The MARSS package seems to require that *w *and *v *have the same dimensions as the state and observation equations, respectively. For example, a model with 4 states in the state equation would need to have four error terms and a 4x4 covariance matrix Q. My questions is whether there is any way to get around this restriction either by - adding a *p x m *coefficient matrix in front of *w*, where *p *is the number of error terms and *m *is the number of state equations, thus allowing the error term of each of the *m *companies to be a linear combination of *p *independent error terms, OR - by specifying the correlation structure in *Q *appropriately. When I attempt to restrict *Q* in a way that mimics the model that would be created by a coefficient matrix like one described above I run into the problem that expressions defining values of entries in *Q* must be linear in parameters. This prevents me from e.g. writing expressions that are products of estimated correlation coefficients. I found a similar issue when investigating the dlm package, but am also looking for suggestions on other approaches to try. *Some more detail:* Currently in MARSS, the equations look like this: - X_t = B_t X_{t-1} + u_t + w_t where X is mx1, B is mxm, u is mx1, w is mx1 - Y_t = Z_t X_t + a_t + v_t where Y is nx1, Z is nxm, X is mx1, a is nx1, v is nx1 My goal is to write error terms as linear combinations, yielding something like: - X_t = B_t X_{t-1} + u_t + R_t w_t where X is mx1, B is mxm, u is mx1, R is pxm, w is px1 - Y_t = Z_t X_t + a_t + S_t v_t where Y is nx1, Z is nxm, X is mx1, a is nx1, S is qxn, v is qx1 *Thanks so much for the help!* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unexpected behavior of apply when FUN=sample
This is Circle 8.1.47 of 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ Pat On 14/05/2013 09:52, Luca Nanetti wrote: Dear experts, I wanted to signal a peculiar, unexpected behaviour of 'apply'. It is not a bug, it is per spec, but it is so counterintuitive that I thought it could be interesting. I have an array, let's say test, dim=c(7,5). test - array(1:35, dim=c(7, 5)) test [,1] [,2] [,3] [,4] [,5] [1,]18 15 22 29 [2,]29 16 23 30 [3,]3 10 17 24 31 [4,]4 11 18 25 32 [5,]5 12 19 26 33 [6,]6 13 20 27 34 [7,]7 14 21 28 35 I want a new array where the content of the rows (columns) are permuted, differently per row (per column) Let's start with the columns, i.e. the second MARGIN of the array: test.m2 - apply(test, 2, sample) test.m2 [,1] [,2] [,3] [,4] [,5] [1,]1 10 18 23 32 [2,]79 16 25 30 [3,]6 14 17 22 33 [4,]4 11 15 24 34 [5,]2 12 21 28 31 [6,]58 20 26 29 [7,]3 13 19 27 35 perfect. That was exactly what I wanted: the content of each column is shuffled, and differently for each column. However, if I use the same with the rows (MARGIIN = 1), the output is transposed! test.m1 - apply(test, 1, sample) test.m1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]12345 13 21 [2,] 22 30 17 18 19 20 35 [3,] 15 23 24 32 26 27 14 [4,] 29 16 31 25 33 34 28 [5,]89 10 11 1267 In other words, I wanted to permute the content of the rows of test, and I expected to see in the output, well, the shuffled rows as rows, not as column! I would respectfully suggest to make this behavior more explicit in the documentation. Kind regards, Luca Nanetti -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 me please: gplot, facets_wrap and ordering of x axis dates
I have a text file of data as below and doing a ggplot line plot of all the ids as separate mini line plots which works with the following code. Problem how do I order the dates for each id plot on the x axis so that the dates are going from oldest to most recent Thanks in advance Dave CODE: a-read.table(DATA,header=TRUE); b-a[order(as.Date(a$date, format=%m/%d/%Y)),] ggplot(data=b) + geom_line(aes(x=date, y=value, group=id, colour= factor(id))) + facet_wrap(~id, scales = free) DATA: id date value 001 8/16/10 0.16 001 10/25/10 0.16 001 11/8/10 0.42 001 11/22/10 0.81 001 12/6/10 0.16 002 8/18/10 2.93 002 10/25/10 2.4 002 11/8/10 1.36 002 11/22/10 1.22 004 8/20/10 0.77 004 10/25/10 0.85 004 11/8/10 1.22 004 11/22/10 0.21 004 12/6/10 1.81 004 10/26/11 0.54 005 6/4/09 1.33 005 6/18/10 1.32 005 8/25/10 2.5 005 9/15/10 1.3 005 10/25/10 1.1 005 11/8/10 0.66 005 11/22/10 0.84 005 12/6/10 7.42 005 11/4/11 1.21 006 9/23/10 0.97 006 10/25/10 2.25 006 11/8/10 0.51 006 11/22/10 0.53 006 12/6/10 0.41 008 8/25/10 3.14 008 10/25/10 3.58 008 11/8/10 2.41 008 12/6/10 2.08 008 6/11/12 3.2 009 10/6/10 0.24 009 11/22/10 0.34 009 2/2/11 0.58 009 2/16/11 0.54 009 3/2/11 0.25 009 3/16/11 0.39 010 9/14/10 0.28 010 2/2/11 0.19 010 2/16/11 0.42 010 3/2/11 0.39 010 3/16/11 0.26 011 8/20/10 0.16 011 2/2/11 0.16 011 2/16/11 0.16 011 3/2/11 0.16 011 3/16/11 1.76 011 10/26/11 0.16 012 12/14/10 0.48 012 2/2/11 1.2 012 2/16/11 0.44 012 3/2/11 0.32 012 3/16/11 0.34 013 11/13/09 0.73 013 8/19/10 3.32 013 2/2/11 13.7 014 2/6/13 1.35 014 4/24/13 0.85 014 8/18/10 0.66 014 10/5/10 0.68 014 10/27/10 0.53 014 2/2/11 0.54 014 2/16/11 0.49 014 3/2/11 0.31 014 3/16/11 0.4 014 6/29/11 0.53 014 8/15/11 0.55 014 8/15/12 0.94 014 10/31/12 0.74 015 12/10/10 0.4 015 2/2/11 0.44 015 3/2/11 0.38 015 3/16/11 0.43 016 12/17/10 0.18 016 1/25/11 0.16 016 2/2/11 0.53 016 2/2/11 0.54 016 2/16/11 0.46 016 3/2/11 0.29 016 3/16/11 0.2 016 3/20/12 0.18 016 3/26/12 0.23 016 3/30/12 0.52 016 4/2/12 0.33 016 4/23/12 0.3 017 11/17/11 3.35 017 12/9/11 2.56 018 2/25/13 18.1 018 3/11/13 14.9 018 3/25/13 11.1 018 4/10/13 8.47 018 4/22/13 15.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 me please: gplot, facets_wrap and ordering of x axis dates
Thank you for supplying the code. It would be easier to help you if we also had some data to work with. ?dput https://github.com/hadley/devtools/wiki/Reproducibility I think reorder() is likely to do the trick but I don't have enough time to mock up some data and check at the moment. Have a look at http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot Good luck. John Kane Kingston ON Canada -Original Message- From: david_ly...@yahoo.com Sent: Tue, 14 May 2013 12:59:07 -0700 (PDT) To: r-help@r-project.org Subject: [R] Help me please: gplot, facets_wrap and ordering of x axis dates I have a text file of data as below and doing a ggplot line plot of all the ids as separate mini line plots which works with the following code. Problem how do I order the dates for each id plot on the x axis so that the dates are going from oldest to most recent Thanks in advance Dave CODE: a-read.table(DATA,header=TRUE); b-a[order(as.Date(a$date, format=%m/%d/%Y)),] ggplot(data=b) + geom_line(aes(x=date, y=value, group=id, colour= factor(id))) + facet_wrap(~id, scales = free) DATA: id date value 001 8/16/10 0.16 001 10/25/10 0.16 001 11/8/10 0.42 001 11/22/10 0.81 001 12/6/10 0.16 002 8/18/10 2.93 002 10/25/10 2.4 002 11/8/10 1.36 002 11/22/10 1.22 004 8/20/10 0.77 004 10/25/10 0.85 004 11/8/10 1.22 004 11/22/10 0.21 004 12/6/10 1.81 004 10/26/11 0.54 005 6/4/09 1.33 005 6/18/10 1.32 005 8/25/10 2.5 005 9/15/10 1.3 005 10/25/10 1.1 005 11/8/10 0.66 005 11/22/10 0.84 005 12/6/10 7.42 005 11/4/11 1.21 006 9/23/10 0.97 006 10/25/10 2.25 006 11/8/10 0.51 006 11/22/10 0.53 006 12/6/10 0.41 008 8/25/10 3.14 008 10/25/10 3.58 008 11/8/10 2.41 008 12/6/10 2.08 008 6/11/12 3.2 009 10/6/10 0.24 009 11/22/10 0.34 009 2/2/11 0.58 009 2/16/11 0.54 009 3/2/11 0.25 009 3/16/11 0.39 010 9/14/10 0.28 010 2/2/11 0.19 010 2/16/11 0.42 010 3/2/11 0.39 010 3/16/11 0.26 011 8/20/10 0.16 011 2/2/11 0.16 011 2/16/11 0.16 011 3/2/11 0.16 011 3/16/11 1.76 011 10/26/11 0.16 012 12/14/10 0.48 012 2/2/11 1.2 012 2/16/11 0.44 012 3/2/11 0.32 012 3/16/11 0.34 013 11/13/09 0.73 013 8/19/10 3.32 013 2/2/11 13.7 014 2/6/13 1.35 014 4/24/13 0.85 014 8/18/10 0.66 014 10/5/10 0.68 014 10/27/10 0.53 014 2/2/11 0.54 014 2/16/11 0.49 014 3/2/11 0.31 014 3/16/11 0.4 014 6/29/11 0.53 014 8/15/11 0.55 014 8/15/12 0.94 014 10/31/12 0.74 015 12/10/10 0.4 015 2/2/11 0.44 015 3/2/11 0.38 015 3/16/11 0.43 016 12/17/10 0.18 016 1/25/11 0.16 016 2/2/11 0.53 016 2/2/11 0.54 016 2/16/11 0.46 016 3/2/11 0.29 016 3/16/11 0.2 016 3/20/12 0.18 016 3/26/12 0.23 016 3/30/12 0.52 016 4/2/12 0.33 016 4/23/12 0.3 017 11/17/11 3.35 017 12/9/11 2.56 018 2/25/13 18.1 018 3/11/13 14.9 018 3/25/13 11.1 018 4/10/13 8.47 018 4/22/13 15.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Post hoc test for GLM with poisson distribution
Hi R-people, I performed controlled experiments to evaluated the seeds germination of two palms under four levels of water treatments. I conducted a generalized linear model (GLM) with a Poisson distribution to verify whether there were significant differences in the number of seed germination (NS-count variable) between treatments and species (explanatory variables). Thus, my model and output were: model1-glm(NS~Treatments*Species, family=poisson) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.562470.57544 4.4538.46e-06 *** Treatments -2.072670.35065 -5.911 3.40e-09 *** Species -0.003120.30527 -0.010 0.992 Treatments:Species 0.903970.17896 5.051 4.39e-07 *** Null deviance: 379.870 on 98 degrees of freedom Residual deviance: 68.302 on 95 degrees of freedom There is a significant interaction between treatments:species. Which is the post hoc test appropriate for this model? Thanks, Maria Isabel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] need means on all boxplots, but only half of them got that
boxplot( Daten$weight~interaction(Daten$Dosis,Daten$sex, drop=TRUE)) means-tapply( Daten$weight, Daten$Dosis, mean) points(means, pch=5, col=red, lwd=5) ...only the boxplots for male got that point on them, its really weird because I don't think that I separated the sex in the codes above Look again; the boxplot is clearly distinguished by sex. Try means-tapply( Daten$weight, interaction(Daten$Dosis,Daten$sex, drop=TRUE), mean) S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 me please: gplot, facets_wrap and ordering of x axis dates
Your value column will be input as character because of the signs and you need to convert the dates in %m/%d/%y format to real R dates. -- David Sent from my iPhone On May 14, 2013, at 3:59 PM, David Lyon david_ly...@yahoo.com wrote: I have a text file of data as below and doing a ggplot line plot of all the ids as separate mini line plots which works with the following code. Problem how do I order the dates for each id plot on the x axis so that the dates are going from oldest to most recent Thanks in advance Dave CODE: a-read.table(DATA,header=TRUE); b-a[order(as.Date(a$date, format=%m/%d/%Y)),] ggplot(data=b) + geom_line(aes(x=date, y=value, group=id, colour= factor(id))) + facet_wrap(~id, scales = free) DATA: id datevalue 001 8/16/10 0.16 001 10/25/100.16 001 11/8/10 0.42 001 11/22/100.81 001 12/6/10 0.16 002 8/18/10 2.93 002 10/25/102.4 002 11/8/10 1.36 002 11/22/101.22 004 8/20/10 0.77 004 10/25/100.85 004 11/8/10 1.22 004 11/22/100.21 004 12/6/10 1.81 004 10/26/110.54 005 6/4/09 1.33 005 6/18/10 1.32 005 8/25/10 2.5 005 9/15/10 1.3 005 10/25/101.1 005 11/8/10 0.66 005 11/22/100.84 005 12/6/10 7.42 005 11/4/11 1.21 006 9/23/10 0.97 006 10/25/102.25 006 11/8/10 0.51 006 11/22/100.53 006 12/6/10 0.41 008 8/25/10 3.14 008 10/25/103.58 008 11/8/10 2.41 008 12/6/10 2.08 008 6/11/12 3.2 009 10/6/10 0.24 009 11/22/100.34 009 2/2/11 0.58 009 2/16/11 0.54 009 3/2/11 0.25 009 3/16/11 0.39 010 9/14/10 0.28 010 2/2/11 0.19 010 2/16/11 0.42 010 3/2/11 0.39 010 3/16/11 0.26 011 8/20/10 0.16 011 2/2/11 0.16 011 2/16/11 0.16 011 3/2/11 0.16 011 3/16/11 1.76 011 10/26/110.16 012 12/14/100.48 012 2/2/11 1.2 012 2/16/11 0.44 012 3/2/11 0.32 012 3/16/11 0.34 013 11/13/090.73 013 8/19/10 3.32 013 2/2/11 13.7 014 2/6/13 1.35 014 4/24/13 0.85 014 8/18/10 0.66 014 10/5/10 0.68 014 10/27/100.53 014 2/2/11 0.54 014 2/16/11 0.49 014 3/2/11 0.31 014 3/16/11 0.4 014 6/29/11 0.53 014 8/15/11 0.55 014 8/15/12 0.94 014 10/31/120.74 015 12/10/100.4 015 2/2/11 0.44 015 3/2/11 0.38 015 3/16/11 0.43 016 12/17/100.18 016 1/25/11 0.16 016 2/2/11 0.53 016 2/2/11 0.54 016 2/16/11 0.46 016 3/2/11 0.29 016 3/16/11 0.2 016 3/20/12 0.18 016 3/26/12 0.23 016 3/30/12 0.52 016 4/2/12 0.33 016 4/23/12 0.3 017 11/17/113.35 017 12/9/11 2.56 018 2/25/13 18.1 018 3/11/13 14.9 018 3/25/13 11.1 018 4/10/13 8.47 018 4/22/13 15.9 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] empirical and GPD for time series simulation
Hi, Does anyone know how to simulate a long time series (say 1000 daily series) or generally a series, with inverse empirical distribution and generalized pareto distribution (meaning to say the time series has a marginal distribution of empirical and GPD distribution.) using the R package? Does anybody know if there is a package in R that do this thing? Thanks in advance, B [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to capture the expression corresponding to the i param in the [ function
I think you need to read ?setClass and ?setMethod. There is an example of defining a [ method for a class that inherits from 'data.frame'. I suspect you need to capture the various possibilities for the arguments being present or missing. -- David Sent from my iPhone On May 14, 2013, at 5:45 AM, Nhan Vu Lam Chi nhani...@adatao.com wrote: Dear David, First, I would like to say thank you for your very soon reply. Second, I want to clarify the question because it seems to not carrying exactly what I want to ask. Let take an example on R data.frame: V1 - 1 df2 - df[V1== 1,] # df is a data.frame, this command is correct, right? The evaluation steps for the above command are: 1. R evaluate V1 1 to get TRUE 2. The command becomes df2 - df[TRUE,] which copies all rows of df to df2 What I want is to capture the V1 1 expression instead of letting R do the evaluation in case of the custom [ function. Assume my class is mydf, the S4 function should be: setMethod([, signature(x=mydf), function(x,i,j,...,drop=TRUE) { e - substitute(i) // do parsing and custom-evaluation tasks }) Currently, i is always a vector of type character, numeric or logic due to R evaluation. I am a newbie to R, so please tolerate my mistakes or misunderstanding. Thanks! Nhan Vu On Tue, May 14, 2013 at 12:14 PM, David Winsemius dwinsem...@comcast.net wrote: On May 13, 2013, at 6:38 PM, Nhan Vu Lam Chi wrote: Hi everyone, I currently work on a S4 class that has the [ function. I want to capture the unevaluated expression corresponding to the i param using substitute() function and do a non-standard evaluation. However R automatically evaluates the expression and give me its value. For example: Given mydf[mydf$V1 1,] with mydf is an object of my custom S4 dataframe class and V1 is one of its columns, I want to get the unevaluated expression mydf$V1 1. My questions are: 1. Is it possible to do that in R? 2. If yes, how to do? Doesn't this cry out for the S4 class definition of [ to be answerable?. Because [ is generic, it could have almost any definition at the whim of the package author. My R version and OS info are: R version 2.15.3 (2013-03-01) -- Security Blanket Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) This is the first time I post to the mailing list, so please forgive any mistakes and/or advise me if possible. Regards, Nhan Vu [[alternative HTML version deleted]] You are forgiven, but this once, for posting in HTML. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing Order of Factor Levels in Mixed Model (nlme)
Edward Patzelt patze003 at umn.edu writes: R Help - Why is that in the results below, changing the order of the factor (trialType2: levels - DD, SD, DS, SS) changes the estimates in the fixed effects tests? I think you're not doing what you expected. By sorting the factor, you are _not_ changing the order of the factor levels (which you might have been trying to do in order to change the parameterization); rather, you're changing the actual order of the observations of the factor, which is scrambling their association with the other variables (response=proportion.down and the grouping variable, subject). I can't think of a scenario under which sorting the order of only one of the variables in the data frame is not a mistake, unless you're trying to randomize the order to do a permutation test. What you might have meant to do is to change the order of the _levels_ of the factor, which you can do via tmp.dat4$trialType2 - factor(tmp.dat4$trialType2, levels=c(DD,SD,DS,SS)) or perhaps tmp.dat4 - transform(tmp.dat4, trialType2=factor(trialType2,levels=sort(levels(trialType2 (see also ?relevel and ?reorder) Changing the order of the factor levels will also change the specific estimates of the fixed-effect parameters, in this case by changing the parameterization (contrasts), which are by default based on differences from the first factor level (although see also ?contr.SAS), but not the overall meaning/fit of the model. By the way, this isn't specifically a mixed-effects model question -- the same issues would apply with just about any statistical model in R (see e.g. Faraway's books on linear and generalized models -- some early drafts are available in the contributed documentation section). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 capture the expression corresponding to the i param in the [ function
On May 14, 2013, at 8:02 PM, David Winsemius wrote: I think you need to read ?setClass and ?setMethod. There is an example of defining a [ method for a class that inherits from 'data.frame'. I suspect you need to capture the various possibilities for the arguments being present or missing. setClass(myFrame, contains = data.frame, representation(callexp = character)) df1 - data.frame(x = 1:10, y = rnorm(10), z = sample(letters,10)) mydf1 - new(myFrame, df1, callexp = ) setMethod([, signature(x = myFrame), function (x, i, j, ..., drop = TRUE) {callexp - deparse(substitute(i)) S3Part(x) - callNextMethod() x@callexp - callexp x } ) mydf1[1:2, ] #-- Object of class myFrame x y z 1 1 -1.9119574 f 2 2 0.2719548 i Slot callexp: [1] 1:2 mydf1[mydf1$x5, ] Object of class myFrame x y z 1 1 -0.1065694 u 2 2 0.8571367 l 3 3 1.7259175 z 4 4 0.3618450 x Slot callexp: [1] mydf1$x 5 -- David Sent from my iPhone On May 14, 2013, at 5:45 AM, Nhan Vu Lam Chi nhani...@adatao.com wrote: Dear David, First, I would like to say thank you for your very soon reply. Second, I want to clarify the question because it seems to not carrying exactly what I want to ask. Let take an example on R data.frame: V1 - 1 df2 - df[V1== 1,] # df is a data.frame, this command is correct, right? The evaluation steps for the above command are: 1. R evaluate V1 1 to get TRUE 2. The command becomes df2 - df[TRUE,] which copies all rows of df to df2 What I want is to capture the V1 1 expression instead of letting R do the evaluation in case of the custom [ function. Assume my class is mydf, the S4 function should be: setMethod([, signature(x=mydf), function(x,i,j,...,drop=TRUE) { e - substitute(i) // do parsing and custom-evaluation tasks }) Currently, i is always a vector of type character, numeric or logic due to R evaluation. I am a newbie to R, so please tolerate my mistakes or misunderstanding. Thanks! Nhan Vu On Tue, May 14, 2013 at 12:14 PM, David Winsemius dwinsem...@comcast.net wrote: On May 13, 2013, at 6:38 PM, Nhan Vu Lam Chi wrote: Hi everyone, I currently work on a S4 class that has the [ function. I want to capture the unevaluated expression corresponding to the i param using substitute() function and do a non-standard evaluation. However R automatically evaluates the expression and give me its value. For example: Given mydf[mydf$V1 1,] with mydf is an object of my custom S4 dataframe class and V1 is one of its columns, I want to get the unevaluated expression mydf$V1 1. My questions are: 1. Is it possible to do that in R? 2. If yes, how to do? Doesn't this cry out for the S4 class definition of [ to be answerable?. Because [ is generic, it could have almost any definition at the whim of the package author. My R version and OS info are: R version 2.15.3 (2013-03-01) -- Security Blanket Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) This is the first time I post to the mailing list, so please forgive any mistakes and/or advise me if possible. Regards, Nhan Vu [[alternative HTML version deleted]] You are forgiven, but this once, for posting in HTML. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R-Help: nparLD Package Non-parametric Repeated Measures
Hi, I'm trying to analyze repeated measurements of body temperature data collected from 7 randomly chosen subjects (e.g. turtles). I am using R, along with the nparLD package to test for an effect of diel period (fixed factor: day or night) and season (sub-plot fixed factor: spring, summer, fall) on body temperature. Based on this set-up (LD-F2), I am using the non-parametric nparLD pacakge([url]http://www.inside-r.org/packages/cran/nparLD/docs/ld.f2[/url]) because data transformations were unsuccessful and I am randomly missing some paired values. Main issue/question: In R the nparLD ANOVA-type Test showed a significant p-value for diel period, no effect of season, and no interaction between diel period and season. But a post-hoc Wilcoxon Signed-Rank Test did NOT find a significant difference (p = 0.054) for diel period (day vs night) body temperature. How is it possible to have a significant effect for day vs night, based on the nparLD package, but NO significant difference between day and night for the post-hoc Wilcoxon test? Also, if I only have two levels of the fixed effect (day vs night), do I need to run a post-hoc test or just look at the mean values after the ANOVA-type test? Data info: The repeated measurements on the 7 subjects had 2 fixed effects: 1. Diel period (day or night) 2. Season (Spring, summer, and fall)(Subplot Factor) Mean values for body temperature and for diel period are below. Diel column (D=Day, N = Night). State column (RT=Spring, RF = Summer, PT = Fall). Subject, N=7. NA = missing value. All comments (good and bad) are greatly appreciated! Thanks, James -- output of sessionInfo(): [code] data=read.csv(file.choose(), header=TRUE) attach(data) data stp diel state subject 1 26.2DRT 1 2 26.4NRT 1 3 24.1DRT 2 4NANRT 2 5NADRT 3 6 25.2NRT 3 7 27.1DRT 4 8 26.5NRT 4 9 26.9DRT 5 10 27.1NRT 5 11 26.2DRT 6 12 26.0NRT 6 13 26.3DRT 7 14 26.7NRT 7 15 26.0DRF 1 16 26.6NRF 1 17 24.2DRF 2 18 25.6NRF 2 19 25.6DRF 3 20 26.6NRF 3 21 26.1DRF 4 22 26.9NRF 4 23 27.2DRF 5 24 27.4NRF 5 25 26.2DRF 6 26 26.7NRF 6 27 27.2DRF 7 28 27.5NRF 7 29 25.0DPT 1 30 24.8NPT 1 31 NADPT 2 32 NANPT 2 33 NADPT 3 34 NANPT 3 35 26.7DPT 4 36 26.9NPT 4 37 27.6DPT 5 38 27.5NPT 5 39 25.2DPT 6 40 24.9NPT 6 41 27.1DPT 7 42 27.0NPT 7 ex.f2-ld.f2(y=stp, time1=diel, time2=state, subject=subject, time1.name=Diel, time2.name=State, description=FALSE) ex.f2$ANOVA.test Statistic dfp-value Diel 4.9028447 1.00 0.02681249 State 0.2332795 1.374320 0.70586274 Diel:State 2.1937783 1.062943 0.13717393 [/code] [code] detach(data) data=read.csv(file.choose(), header=TRUE) attach(data) data day night 1 26.2 26.4 2 26.0 26.6 3 25.0 24.8 4 24.2 25.6 5 25.6 26.6 6 27.1 26.5 7 26.1 26.9 8 26.7 26.9 9 26.9 27.1 10 27.2 27.4 11 27.6 27.5 12 26.2 26.0 13 26.2 26.7 14 25.2 24.9 15 26.3 26.7 16 27.2 27.5 17 27.1 27.0 library(coin) wilcoxsign_test(day ~ night, distribution=exact) Exact Wilcoxon-Signed-Rank Test data: y by x (neg, pos) stratified by block Z = -1.9234, p-value = 0.05482 alternative hypothesis: true mu is not equal to 0 [/code] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Broken line questions
Hi, It is because of the unequal lengths of x and y. I was able to plot without the errors. But, not sure if this is what you wanted. mydata - read.table(TestData.csv, header=TRUE, sep=\t) reg1-lm(MW01~Year,data=mydata) plot(MW01~Year,data=mydata[!is.na(mydata$MW01),],col=ifelse(D_MW01,black,red),ylab=END (mg/L),pch=ifelse(D_MW01,19,24),cex=1) with(mydata[!is.na(mydata$MW01),],lines(Year,MW01,lty=c(1),col=black)) plx1-predict(loess(MW01 ~ Year, data=mydata[!is.na(mydata$MW01),]), se=T) #rough ready CI by adding and subtracting 2 times the standard error to the mean lines(mydata[!is.na(mydata$MW01),Year],plx1$fit+2*plx1$s, lty=2) lines(mydata[!is.na(mydata$MW01),Year],plx1$fit-2*plx1$s, lty=2) mydata1-mydata[!is.na(mydata$MW01),2:3] y.loess - loess(y ~ x, span=0.8, data.frame(x=mydata1$Year,y=mydata1$MW01)) # Compute loess smoothed values for all points along the curve y.predict - predict(y.loess, data.frame(x=mydata1$Year)) # Plots the curve. lines(mydata1$Year,y.predict, lty=2, lwd=2) BTW, Non-detect in the legend is not clear. A.K. #Add line between the points lines(mydata1$Year,mydata1$MW01) From: David Doyle kydaviddo...@gmail.com To: arun smartpink...@yahoo.com Sent: Tuesday, May 14, 2013 11:10 PM Subject: Re: [R] Broken line questions Hi, I'm trying to do something very similar to the graph before and I got the broken line problem fixed with your example. On this one I'm trying to add 2 times the standard error (approxmating a 10% confidence) onto the LOESS curve. The data is at https://docs.google.com/file/d/0B0CqEkyKWiq9SjFwemRhZnV4aTA/edit?usp=sharing (sorry I don't have access to my FTP right now.) When I use the code below, I get Error in xy.coords(x, y) : 'x' and 'y' lengths differ I assume this is because there are blanks in the data. Any suggestions??? The code I'm using is: #set the dir to where you data is setwd(c:/R) #Load your data. The data is in a spreadsheet named nd-spreadsheet and we are going to call it data in R mydata - read.table(TestData.csv, header=TRUE, sep=,,) attach(mydata) reg1 - lm(MW01~Year) par(cex=1) #Plots the data but makes nondetects a different color and type based on column D_MW01 being a 0 for ND and 1 for detect. plot(MW01~Year,data=mydata[!is.na(mydata$MW01),], col=ifelse (D_MW01, black, red),ylab = EMD (mg/L), pch=ifelse(D_MW01, 19, 24), cex = 1) with(mydata[!is.na(mydata$MW01),],lines(Year,MW01,lty=c(1),col=black)) plx-predict(loess(MW01 ~ Year, data=mydata), se=T) #rough ready CI by adding and subtracting 2 times the standard error to the mean lines(mydata$Year,plx$fit+2*plx$s, lty=2) lines(mydata$Year,plx$fit-2*plx$s, lty=2) # Apply loess smoothing using the default span value of 0.8. You can change the curve by changing the span value. y.loess - loess(y ~ x, span=0.8, data.frame(x=Year, y=MW01)) # Compute loess smoothed values for all points along the curve y.predict - predict(y.loess, data.frame(x=Year)) # Plots the curve. lines(Year,y.predict, lty=2, lwd=2) #Add line between the points lines(Year,MW01) #Add Legend to MW01. You can change the size of the box by changing cex = 0.75 Large # makes it larger. legend (topleft, c(Smoothing Curve,Detect,Non-Detect), col = c(1,1,1), cex = 1, text.col = black, lty = c(2,-1,-1), lwd = c(2,-1,-1), pch = c(-1,19,24), merge = TRUE, bg = 'gray90') #Add title title(main=MW01) # Done Thanks again David On Sun, May 12, 2013 at 10:11 AM, arun smartpink...@yahoo.com wrote: No problem, Regards, Arun From: David Doyle kydaviddo...@gmail.com To: arun smartpink...@yahoo.com Sent: Sunday, May 12, 2013 8:03 AM Subject: Re: [R] Broken line questions Thanks! That took care of it. On Sat, May 11, 2013 at 10:01 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps: plot(dataset1~Date,data=mydata[!is.na(mydata$dataset1),],ylim=range(5.7,8),pch=10,cex=0.8,col=black,xlab=Date,ylab=pH) with(mydata[!is.na(mydata$dataset2),],points(Date,dataset2,col=blue,pch=2,cex=0.8)) with(mydata[!is.na(mydata$dataset3),],points(Date,dataset3,col=red,pch=2,cex=0.8)) with(mydata[!is.na(mydata$dataset1),],lines(Date,dataset1,lty=c(1),col=black)) with(mydata[!is.na(mydata$dataset2),],lines(Date,dataset2,lty=c(1),col=blue)) with(mydata[!is.na(mydata$dataset3),],lines(Date,dataset3,lty=c(1),col=red)) A.K. - Original Message - From: David Doyle kydaviddo...@gmail.com To: r-help@r-project.org Cc: Sent: Saturday, May 11, 2013 10:22 PM Subject: [R] Broken line questions Hello Everyone, I have some data that like most real world data isn't complete. I'm trying to plot all of it together with lines connecting the data points. Because I have breaks in the data I have breaks in the lines. Is there a way that the lines will connect all the markers??? Below is the code. Thanks in advance. David #Load your data. The data is in a spreadsheet named KW-spreadsheet and we
Re: [R] Sampling Weights and lmer() update?
Arguably you are looking in the wrong place (there's a special mixed-models mailing list for R), but I can answer the question. No. At least, there's nothing in lme4, and I haven't done anything (since I want a more general solution than Stata and MLWiN implement) and I'd be surprised if someone else had done it. -thomas On Tue, May 14, 2013 at 3:35 PM, Richard Blissett rsl.bl...@gmail.comwrote: Perhaps I am not looking in the right place, but I am looking for a way to use lmer() to run a multilevel model that incorporates sampling weights. I have used the Lumley survey package to use sampling weights in the past, but according to post I found online from Thomas Lumley in mid-2012, R is currently not equipped to be able to do this. His post is here: http://r.789695.n4.nabble.com/sampling-weights-for-multilevel-models-tp4632947p4632955.html Does anyone know if there has been an update since then to be able to do this, or if there's another way to go about doing this in R? Otherwise, I am thinking that I will have to move my data over to Stata and try to run the multilevel models there. Richard -- Richard Blissett Eco-Tip: Before printing, please consider whether you really need to have this email on paper. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Thomas Lumley Professor of Biostatistics University of Auckland [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Post hoc test for GLM with poisson distribution
On May 14, 2013, at 21:04 , Bel Braz wrote: Hi R-people, I performed controlled experiments to evaluated the seeds germination of two palms under four levels of water treatments. I conducted a generalized linear model (GLM) with a Poisson distribution to verify whether there were significant differences in the number of seed germination (NS-count variable) between treatments and species (explanatory variables). Thus, my model and output were: model1-glm(NS~Treatments*Species, family=poisson) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 2.562470.57544 4.4538.46e-06 *** Treatments -2.072670.35065 -5.911 3.40e-09 *** Species -0.003120.30527 -0.010 0.992 Treatments:Species 0.903970.17896 5.051 4.39e-07 *** Null deviance: 379.870 on 98 degrees of freedom Residual deviance: 68.302 on 95 degrees of freedom There is a significant interaction between treatments:species. Which is the post hoc test appropriate for this model? There's not much post hoc testing to do if the effect is described by a single coefficient. Did you forget to code Treatments as a factor variable? Apart from that, it depends on what you want to do. Do you want to know where the interaction comes from, or just within which treatment(s) there is a species effect? Since there is only two species, the easiest way forward is to compute the four species effects, one for each treatment. You can then compare the effects pairwise (6 comparisons) or compare each effect to zero (4 comparison). I don't think you can do much better than simple Bonferroni corrections in either case. Thanks, Maria Isabel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Broken line questions
Hi, You may also replace the NAs using ?na.approx() from library(zoo). library(zoo) mydata2- mydata mydata2$MW01-na.approx(mydata2$MW01) plot(MW01~Year,data=mydata2,col=ifelse(D_MW01,black,red),ylab=END (mg/L),pch=ifelse(D_MW01,19,24),cex=1) with(mydata2,lines(Year,MW01,lty=c(1),col=black)) plx-predict(loess(MW01 ~ Year, data=mydata2), se=T) lines(mydata2$Year,plx$fit+2*plx$s, lty=2) lines(mydata2$Year,plx$fit-2*plx$s, lty=2) y.loess - loess(y ~ x, span=0.8, data.frame(x=mydata2$Year,y=mydata2$MW01)) y.predict - predict(y.loess, data.frame(x=mydata2$Year)) lines(mydata2$Year,y.predict, lty=2, lwd=2) legend (topleft, c(Smoothing Curve,Detect,Non-Detect), col = c(1,1,1), cex = 1, text.col = black, lty = c(2,-1,-1), lwd = c(2,-1,-1), pch = c(-1,19,24), merge = TRUE, bg = 'gray90') A.K. - Original Message - From: arun smartpink...@yahoo.com To: David Doyle kydaviddo...@gmail.com Cc: R help r-help@r-project.org Sent: Tuesday, May 14, 2013 11:52 PM Subject: Re: [R] Broken line questions Hi, It is because of the unequal lengths of x and y. I was able to plot without the errors. But, not sure if this is what you wanted. mydata - read.table(TestData.csv, header=TRUE, sep=\t) reg1-lm(MW01~Year,data=mydata) plot(MW01~Year,data=mydata[!is.na(mydata$MW01),],col=ifelse(D_MW01,black,red),ylab=END (mg/L),pch=ifelse(D_MW01,19,24),cex=1) with(mydata[!is.na(mydata$MW01),],lines(Year,MW01,lty=c(1),col=black)) plx1-predict(loess(MW01 ~ Year, data=mydata[!is.na(mydata$MW01),]), se=T) #rough ready CI by adding and subtracting 2 times the standard error to the mean lines(mydata[!is.na(mydata$MW01),Year],plx1$fit+2*plx1$s, lty=2) lines(mydata[!is.na(mydata$MW01),Year],plx1$fit-2*plx1$s, lty=2) mydata1-mydata[!is.na(mydata$MW01),2:3] y.loess - loess(y ~ x, span=0.8, data.frame(x=mydata1$Year,y=mydata1$MW01)) # Compute loess smoothed values for all points along the curve y.predict - predict(y.loess, data.frame(x=mydata1$Year)) # Plots the curve. lines(mydata1$Year,y.predict, lty=2, lwd=2) BTW, Non-detect in the legend is not clear. A.K. #Add line between the points lines(mydata1$Year,mydata1$MW01) From: David Doyle kydaviddo...@gmail.com To: arun smartpink...@yahoo.com Sent: Tuesday, May 14, 2013 11:10 PM Subject: Re: [R] Broken line questions Hi, I'm trying to do something very similar to the graph before and I got the broken line problem fixed with your example. On this one I'm trying to add 2 times the standard error (approxmating a 10% confidence) onto the LOESS curve. The data is at https://docs.google.com/file/d/0B0CqEkyKWiq9SjFwemRhZnV4aTA/edit?usp=sharing (sorry I don't have access to my FTP right now.) When I use the code below, I get Error in xy.coords(x, y) : 'x' and 'y' lengths differ I assume this is because there are blanks in the data. Any suggestions??? The code I'm using is: #set the dir to where you data is setwd(c:/R) #Load your data. The data is in a spreadsheet named nd-spreadsheet and we are going to call it data in R mydata - read.table(TestData.csv, header=TRUE, sep=,,) attach(mydata) reg1 - lm(MW01~Year) par(cex=1) #Plots the data but makes nondetects a different color and type based on column D_MW01 being a 0 for ND and 1 for detect. plot(MW01~Year,data=mydata[!is.na(mydata$MW01),], col=ifelse (D_MW01, black, red),ylab = EMD (mg/L), pch=ifelse(D_MW01, 19, 24), cex = 1) with(mydata[!is.na(mydata$MW01),],lines(Year,MW01,lty=c(1),col=black)) plx-predict(loess(MW01 ~ Year, data=mydata), se=T) #rough ready CI by adding and subtracting 2 times the standard error to the mean lines(mydata$Year,plx$fit+2*plx$s, lty=2) lines(mydata$Year,plx$fit-2*plx$s, lty=2) # Apply loess smoothing using the default span value of 0.8. You can change the curve by changing the span value. y.loess - loess(y ~ x, span=0.8, data.frame(x=Year, y=MW01)) # Compute loess smoothed values for all points along the curve y.predict - predict(y.loess, data.frame(x=Year)) # Plots the curve. lines(Year,y.predict, lty=2, lwd=2) #Add line between the points lines(Year,MW01) #Add Legend to MW01. You can change the size of the box by changing cex = 0.75 Large # makes it larger. legend (topleft, c(Smoothing Curve,Detect,Non-Detect), col = c(1,1,1), cex = 1, text.col = black, lty = c(2,-1,-1), lwd = c(2,-1,-1), pch = c(-1,19,24), merge = TRUE, bg = 'gray90') #Add title title(main=MW01) # Done Thanks again David On Sun, May 12, 2013 at 10:11 AM, arun smartpink...@yahoo.com wrote: No problem, Regards, Arun From: David Doyle kydaviddo...@gmail.com To: arun smartpink...@yahoo.com Sent: Sunday, May 12, 2013 8:03 AM Subject: Re: [R] Broken line questions Thanks! That took care of it. On Sat, May 11, 2013 at 10:01 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps: