[R] Split-plot and within-subjects
Dear all, I have a probably silly question on how to specify model for a split-plot design and for a within-subject design (1way). I have two factors: factor A with 5 levels and factor B with 2 levels, for each level of factor A I have 4 subjects that experiment both levels of factor B, so this should be a split-plot design without blocking. I've read tons of vignettes, old emails and whatsoever, but I've found somehow diffrent informations concerning the most appropriate way to code this using aov and lme/lmer. My guesses are as follows: aov(y ~ A * B + Error(Subject), data = mydata) lme(y ~ A * B, random = ~1 | Subject, data = mydata) lmer(y ~ A * B + (1 | Subject), data = mydata) This should provide results for a split-plot design without blocks where F statistics are computed according to the correct error strata am I right? I'm a little bit confused because most examples on help pages and vignettes involve blocking which is not present here. Additionally, suppose that instead of analyzing all the data as a whole I split them according to levels of factor A, thus having 5 different within-subjects models to run, how am I supposed to code the Error terms appropriately? This is what I figured out, yet I'm not sure it's what I want: aov(y ~ B + Error(Subject/B), data = mydata2) lme(y ~ B, random = ~1 | Subject/B, data = mydata2) lmer(y ~ B + (1 | Subject/B), data = mydata2) Thanks Niccolò __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Superposing mean line to xyplot
Dear R-users, I'm using lattice package and function xyplot for the first time so you will excuse me for my inexperience. I'm facing quite a simple problem but I'm having troubles on how to solve it, I've read tons of old mails in the archives and looked at some slides from Deepayan Sarkar but still can not get the point. This is the context. I've got data on 9 microRNAs, each miRNA has been measured on three different arrays and on each array I have 4 replicates for each miRNA, which sums up to a total of 108 measurements. I've the suspect that measurement on the first array are systematically lower than the others so I wanted to draw some line plot where each panel correspond to a miRNA, and each line correspond to one of the four replicates (that is: first replicate of miRNA A on array 1 must be connected to first replicate of miRNA A on array 2 and so on), so that for each panel there are 4 series of three points connected by a line/segment. I've done this easily with lattice doing this: array = rep(c(A,B,C),each = 36) # array replicate spot = rep(1:4,27) # miRNA replicate on each array miRNA = rep(rep(paste(miRNA,1:9,sep=.),each=4),3) # miRNA label exprs = rnorm(mean=2.8,n = 108) # intensity data = data.frame(miRNA,array,spot,exprs) xyplot(exprs ~ array|miRNA,data=data,type=b,groups=spot,xlab=Array,ylab = Intensity,col=black,lty=2:5,scales = list(y = list(relation = free))) Now, I want to superpose to each panel an other series of three points connected by a line, where each point represent the mean of the four replicates of the miRNA on each array, a sort of mean line. I've tried using the following, but it's not working as expected: xyplot(exprs ~ array|miRNA,data=array,type=b,groups=spot,xlab=Array,ylab = Intensity,col=black,lty=2:5,scales = list(y = list(relation = free)), panel = function(x,y,groups,subscripts){ panel.xyplot(x,y,groups=groups,subscripts=subscripts) panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) }) This is maybe a silly question and possibly there's a trivial way to do it, but I can not figure it out. Thanx for any help. niccolò __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Superposing mean line to xyplot
Dear R-users, I'm using lattice package and function xyplot for the first time so you will excuse me for my inexperience. I'm facing quite a simple problem but I'm having troubles on how to solve it, I've read tons of old mails in the archives and looked at some slides from Deepayan Sarkar but still can not get the point. This is the context. I've got data on 9 microRNAs, each miRNA has been measured on three different arrays and on each array I have 4 replicates for each miRNA, which sums up to a total of 108 measurements. I've the suspect that measurement on the first array are systematically lower than the others so I wanted to draw some line plot where each panel correspond to a miRNA, and each line correspond to one of the four replicates (that is: first replicate of miRNA A on array 1 must be connected to first replicate of miRNA A on array 2 and so on), so that for each panel there are 4 series of three points connected by a line/segment. I've done this easily with lattice doing this: array = rep(c(A,B,C),each = 36) # array replicate spot = rep(1:4,27) # miRNA replicate on each array miRNA = rep(rep(paste(miRNA,1:9,sep=.),each=4),3) # miRNA label exprs = rnorm(mean=2.8,n = 108) # intensity data = data.frame(miRNA,array,spot,exprs) xyplot(exprs ~ array|miRNA,data=data,type=b,groups=spot,xlab=Array,ylab = Intensity,col=black,lty=2:5,scales = list(y = list(relation = free))) Now, I want to superpose to each panel an other series of three points connected by a line, where each point represent the mean of the four replicates of the miRNA on each array, a sort of mean line. I've tried using the following, but it's not working as expected: xyplot(exprs ~ array|miRNA,data=array,type=b,groups=spot,xlab=Array,ylab = Intensity,col=black,lty=2:5,scales = list(y = list(relation = free)), panel = function(x,y,groups,subscripts){ panel.xyplot(x,y,groups=groups,subscripts=subscripts) panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) }) This is maybe a silly question and possibly there's a trivial way to do it, but I can not figure it out. Thanx for any help. niccolò __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] profile in lme4 and lme4a/lme4b
Dear R-users, from Douglas Bates lme4 book I'm trying to run profile() on a quite large dataset, in order to have some confidence intervals on random effects parameter in mixed models. When I run it in lme4 however I'm faced with the following error: Errore in UseMethod(profile) : no applicable method for 'profile' applied to an object of class mer Surfing on R-help mailing lists I understood that this has to do with some compatibility problems which are undergoing development for next version of the lme4 package, right? Also, I found that this function is active in the development packages lme4a and lme4b, available from R-forge... I was trying to install these packages, at least to have profile() running. I've tried different ways for doing this but I'm stuck in a blind alley...I've tried the following (all suggestions from R users found on the Internet): - install.packages(lme4a, repos=http://R-Forge.R-project.org;) returning Warning message: In getDependencies(pkgs, dependencies, available, lib) : package lme4a is not available - installing binary file directly in the .libpaths directory, but: lme4a binary for MAC can not be retrieved on the web (page not found), and lme4b gives similar problem. Now only installing package from source files remain, but this does not seem so easy...at least not for me! I have a Macbook Pro (running Mac OS/X 10.6.4 with Leopard)... Any help is appreciated, since previous talks on R mailing list kind of confused me much!! thanx in advance niccolò [[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] Nonparametric MANCOVA using matrices
Dear R-users, is anybody aware of some package or routine to implement nonparametric Multivariate Analysis of Covariance (MANCOVA) using matrices instead of single variable names? I found something for parametric MANCOVA which still requires single variables to be used (ffmanova,vegan), but since both the response matrix and the covariates matrix are quite large (306 and 152 variables, respectively) I have some difficulty in implementing this model... Something like Y ~ X*Z, where X is a design matrix, and Z is the covariate matrix. Rows of both Y and Z are much less than respective columns... Actually, the closest thing i found is the adonis function in the vegan package (I've used it much but only for MANOVA purposes), but still things do not seem to work that properly...namely no residual df is left for estimating residuals SS... thanks for any help! niccolò [[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] partial area under roc curve for fixed levels of TPR
Dear r users a collegue of mine is trying to estimate a partial area under the roc curve by fixing the true positive rate, instead of the false positive rate. This latter is the only avaliable option with the rcomp routine (package: pcvsuite). can anyone help him (and, thus, me) ? thank you in advance Niccolò [[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] If...while...or what else??
Dear R users,I come to you with a quite silly question I think, but I hope you can answer me... That is, I've got some problems in using the if and while conditions in a loop. Substantially, I want to select rows in a dataset depending on an index variable (suppose it ranges from 1 to 5), so to make a specific analysis (homemade of course) on thie new dataset. Mi first tought has been to do a double loop like this: for i in 1:5{ for j in (i+1):5{ data = dataset[(variable==i) | (variable==j),] ##analysis ##analysis } } This way I should select all the couples only once (gaining in efficiency I hope). The fact is that this arrangement has a problem: that j ends up with ranging from 2 to 6, not from to 2 to 5. So when I do a subsetting on the dataset to obtain only the rows corresponding to the values of i and j I want, when the loop comes to j = 6 I have an error, of course. What I want to know is: how can I use the if or while condition in such a loop to avoid the routine doing the computations for this case? I.e., can I tell somehow R Hey, if j=6, let it go and move on with the other computations? Or maybe you can see a faster and better way of using the for conditions?? I hope I made myself clear, if not I'll carify myself!! Thanks in advance Niccolò [[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] rbind for matrices - rep argument
Dear R users,I'm facing a trivial problem, but I really can't solve it. I've tried a dozen of codes, but I can't get the result I want. The question is: I have a dataframe like this one [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,]25549 [3,]16812 [4,]86415 made up of decimal numbers, of course. I want to append this dataframe to itself a number x of times, i.e. 3. That is I want a dataframe like this [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,]25549 [3,]16812 [4,]86415 [5,]12345 [6,]25549 [7,]16812 [8,]86415 [9,]12345 [10,]25549 [11,]16812 [12,]86415 I'm searching for an authomatic way to do this (I've already used the rbind re-writing x times the name of the frame...), as it must enter a function where one argument is exactly the number x of times to repeat this frame. Any ideas?? Thanks in advance! Niccolò [[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] Fwd: multinomial regression for clustered data
Hello dear R-users, does any of you know a way to perform a multinomial regression with clustered data (i.e. repeated measurements)? I made the first analysis with Stata option vce cluster in the mlogit command but was looking for a similar functionality in R too... thanks all! niccolò [[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] Fwd: Empty list to use in a for cycle
Dear R-users, I'm posting a problem I already asked help for some time ago, because I'm facing that problem once again and even because now, reading that old e-mail, and the answer recevied, I understand I've not made myself clear. Here's the question: I need to create an empty list of a specific length to fill it with a quite large amount of square matrices, which is 602. The question is that these matrices are created inside a for cycle, and I do not know how to recall all of them one by one, except by creating an empty list before the cycle, than assigning for each value of the i index the amtrix computed to the first element of the empty list. The fact is that: i've trided to create an empty list with vector(list,602) and then putting it in a cycle, but it didn't work. This is the cycle I've used. To prove it works (and then the cycle itself is not a problem) there's also the output (i.e. the last square matrix computed). for (i in unique(elio2$id)){ sub.mu - exp.mu[exp.mu$id==i,] D - matrix(0,nrow( sub.mu),nrow(sub.mu)) diag(D) - sub.mu$deriv.link A - mat.cov[1:nrow(D),1:nrow(D)] R - corstr[1:nrow(D),1:nrow(D)] W - solve(D)%*%solve(sqrt(A))%*%solve(R)%*%solve(sqrt(A))%*%solve(D) } W [,1] [,2] [,3] [,4] [1,] 3.492489e+02 -7.9324883721 0.0006286788 -0.0031046240 [2,] -7.932488e+00 17.4974625191 -1.7575467817 0.0001403319 [3,] 6.286788e-04 -1.7575467817 17.3227959738 -1.7529916860 [4,] -3.104624e-03 0.0001403319 -1.7529916860 17.2279244622 Does anyone knows how to insert each and every matrix like the one above in a omnicomprehensive list? That's because I've to use a function requiring me to have the matrices I need inside a list. Thanks in advance, hope it's not a too much stupid problem! niccolò [[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] create diagonal matrix within a for cycle
Dear R users, I'm trying to build a diagonal matrix from a group of matrices. These matrices have been built in a for loop. That is, I've subsetted a preliminar matrix to obtain a certain number of square sub-matrices, and now I need to create a diagonal out of these. Suppose my matrix is a square matrix 21x21, and that I want to diagonalize 616 submatrices of this one. To do this I do: diag - rep(1,21) work.cov - matrix(0,21,21) diag(work.cov) - diag samp - sample(seq(1:21),616,replace=T) for (i in 1:length(samp)){ A - work.cov[1:samp[i],1:samp[i]] } Now, I want to put these 616 square matrices on the diagonal of a new matrix. The question is: how I can I do this? I know there's a function bdiag that creates diagonal matrix with various elements (vectors and matrices), but the problem here's that my matrices exists only in the loop, not outside of it, and they all correspond to the same matrix V computed under different values of i. Thansk in advance niccolò [[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] identify number of sequences from a vector
dear R users, I've got kind of strange problem that I can't solve, even though it's not that difficult. I need to compute the wald-wolfowitz run test on the residuals from a gee model, and I'm trying to build the quantities I need by hand. Whereas for the expected and the variance there's no problem, I do not know how to quantify the number of runs, i.e. the number of sequences of equal values. With a short vector like 1 1 1 0 0 1 1 1 1 1 1 it is easy to see 3 sequences, but my residuals are more than 7000, so it's quite difficult to trust on eyes only. I'm looking for a way to get this one, but I can't figure out. Moreover, i found the wawotest function in the adehabitat package doing this test, but the results (which is mean, variance...) are different from what I got by calculatin them by hand so I wanted to finish my calculations to better understand what's going on. Any help will be appreciated. Just give me a hint, and I'll do my best to rule this out... thanks niccolò [[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.