[R] Questions about the glht function for planned comparison
Hi all, I've posted this question before, but did not get any reply. I post it again here and see if anybody can help. Thank you. I have a nested model with the following effects fixed: treatments random: experiment_date I used lme() to model the data mod1 - lme(N_cells ~treatments-1, random=~1|experiment_date, method='ML') Then I want to compare all the other treatments to the control (included in the treatments in mod1). After a fair amount of searching around, I decided to use glht() from the multcomp package (any other suggestions?). lvl.treatments=table(treatments) K = contrMat(lvl.treatments,type='Dunnett',base=1) mc-glht(mod1, linfct=mcp(treatments=K),alternative='greater') But I got the following error: Error in contr.treatment(n = 0L) : not enough degrees of freedom to define contrasts I tried to extract the df parameter using modelparm(), but the function couldn't be applied to lme: Error in UseMethod(modelparm) : no applicable method for 'modelparm' applied to an object of class lme The degree of freedom of the fixed effect was 194. I tried to specify the number in glht, but got the same error as not enough degrees of freedom to define contrasts. Does anyone know what's happening and how I could possibly solve the problem? Thank you so much. Best, Wendy [[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 label certain values on a curve?
This is exactly what I need. Thanks a lot! Best, Wendy On Wed, Jun 6, 2012 at 11:38 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Take a look at the identify() function. Best, Michael On Wed, Jun 6, 2012 at 11:23 AM, Wendy Han wendyha...@gmail.com wrote: Hi all, I have drawn a curve in R and observed some interesting values, I wonder if there is any method to mark certain values on this curve, so that I can manually choose the point and know the exact value of this point simultaneously? I appreciate your suggestions and advice! Thanks a lot! Wendy [[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] igraph find the path with the smallest weights
Hi all, I am trying to analyze some graphs in R. Given a weighted directed network with 7 nodes. I want to find a path from node 1 to node 7, so the sum of all the edges on the path is the smallest comparing to all the other paths. I am wondering if I can do this in igraph. After I identify the path, can I colour code the path? Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/igraph-find-the-path-with-the-smallest-weights-tp4429343p4429343.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] set heatmap.2 color ranges
Hi all, I have a matrix with values between 0 and 1. I want to plot this matrix on a heat map so anything 0.05 is blue, anything =0.05 and 0.01 is yellow, and anything else is grey. I am using the heatmap.2 function. I searched around but did not find an efficient way to set colour ranges as I described. Could anybody give some hints? Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/set-heatmap-2-color-ranges-tp4425166p4425166.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] access results of graph.maxflow and program max-flow algorithm
Hi all, I want to use graph.maxflow function for my work. Given a network, I could get a result, but I could not figure out how the function get the result. Did anyone have the same problem before? How did you resolve it? Does anyone know any other functions/programs for max-flow analysis. Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/access-results-of-graph-maxflow-and-program-max-flow-algorithm-tp4375744p4375744.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] questions about scatterplotMatrix
Hi all, I want to plot some data with scatterplotMatrix. I want to set all axis limits of all the sub figures the same, also add abline(0,1) to all the sub figures. Using the code following code, I can only add abline to the first off-diagonal figure, and I did not figure out how to set all the axis limits the same. scatterplotMatrix(~ income + education + prestige, smooth = FALSE,transform=FALSE, data=Duncan,robust=TRUE,diagonal=none,plot.points = TRUE,reg.line=abline(0,1)) Does anybody know how to achieve this? Any advice is appreciated. Thank you. Wendy -- View this message in context: http://r.789695.n4.nabble.com/questions-about-scatterplotMatrix-tp4167576p4167576.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] permutate elements in a vector
Hi all, I have a vector, e.g., A = c(10, 20, 30, 40). This 4 numbers have 4! = 24 different combination. I want to generate a matrix with one combination in one row, so the output would be B = 10 20 30 40 10 40 20 30 ... Does anyone know how to do this easily in R? Thank you very much. Wendy -- View this message in context: http://r.789695.n4.nabble.com/permutate-elements-in-a-vector-tp4127821p4127821.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] annotate histogram
Hi all, I want to make a histogram like the one show http://nar.oxfordjournals.org/content/39/suppl_1/D1011/F1.expansion.html here , but I did not figure out how to add the red marks at the bottom of the bars. Could anybody help? Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/annotate-histogram-tp3963960p3963960.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] round up a number to 10^4
Hi all, I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and want to round them so the output is Y = c(6, 8, 8). I tried Y-round(X,-4), but it gives me Y = c(6, 7, 8). Do anybody know how to round up a number to 10^4? Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/round-up-a-number-to-10-4-tp3964394p3964394.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] element-by-element comparison
Hi, I have a vector and a matrix. For example, A = [ 12 3 4]; B = [ 4 13 10 2 4 8]; I am comparing A to each column of B using AB[,ii], so the expected result is C = [ 10 01 00]; I am looking for a way to do this quickly instead of going through the for loop, but haven't had any luck yet? Any advice is appreciated. Thank you very much. Wendy -- View this message in context: http://r.789695.n4.nabble.com/element-by-element-comparison-tp3952301p3952301.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] get the sorted index of elements within a column
Hi all, I have matrix, A. I want to sort the elements in each column in a ascending order and output the index number their position. For example A = [,1] [,2] [,3] [,4] [1,] 135.87060 97.55820 121.07722 171.625495 [2,] 70.19811 36.64529 50.13501 6.319125 [3,] 26.86293 24.22025 43.42826 26.952587 [4,] 1.88864 54.97618 12.50913 103.958836 I want the output, B, to be B = [,1] [,2] [,3] [,4] [1,]4444 [2,]3231 [3,]2122 [4,]1313 I tried apply(test,1,order), but it did not work. Could anybody please help? Thank you very much. Wendy -- View this message in context: http://r.789695.n4.nabble.com/get-the-sorted-index-of-elements-within-a-column-tp3896606p3896606.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] reshape a matrix
Hi all, I have a data.frame like following A-c('d0','d0','d1','d1','d2','d2') B-rep(c('control','sample'),3) C-c(rep(10,2),200,300,400,500) dataframe-data.frame(A,B,C) I want to reshape the matrix, so the matrix with 'd0', 'd1' and 'd2' in rows and 'control' and 'sample' in columns. Is there a function for doing this easily? Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/reshape-a-matrix-tp3757179p3757179.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] About How to check if a html directory exists
Dear all, I want to let R automatically download available files from a website in certain folders. Since the files I need, if exist, are in a certain directory, I used download.file() function with a predesigned directory. However, some of the folders do not have the file I want. When this occurs, my program returns error and terminates. So I wonder if there is any way that I can check if a directory exists before downloading that file. I appreciate your help! Thanks! Wendy [[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] count number of TRUEs in each row
Hi all, I have a huge matrix of TRUE/FALSE table like following, and I want to count the number of TRUEs in each row. Instead of looping through each row and do length(Z[Z==TRUE]), I am wondering if there is an easier way of doing this. [,1] [,2][,3] [1,]TRUE FALSE FALSE [2,]FALSE TRUE TRUE Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/count-number-of-TRUEs-in-each-row-tp3440486p3440486.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] plot two pearson correlation matrix on one heatmap
Hi all, I am trying to plot two pearson correlation coefficient matrices on one heatmap using heatmap.2. I combined two matrices as following A = [0.8 0.9; 0.75 0.95] B = [0.82 0.87 0.94 0.74] combined = [0.8 0.9 0 0; 0.75 0.95 0 0 0 0 0.82 0.87 0 0 0.94 0.74] heatmap.2(combined,distfun=function(c) as.dist(1-c),hclustfun=function(c) hclust(c,method=average), race=none, col=greenred(75),trace=none,dendrogram =column) The resultant heatmap having a scale from 0 to 1. I want to ignore the zero elements in the combined matrix and display them in black. Also, I want the scale to be greater than 0.7. I looked at the heatmap.2 webpage, but did not have a clue. Could anybody help me? Thank you in advance. Wendy -- View this message in context: http://r.789695.n4.nabble.com/plot-two-pearson-correlation-matrix-on-one-heatmap-tp3261882p3261882.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] Find the empty element in a factor array
Hi all, I have a factor array, and some of the elements are empty. How would I return the index number of the empty elements. For example, test-factor(c('A','','B','C','E')) test [1] A B C E Levels: A B C E I would like the result equal to 2. Thank you, Wendy -- View this message in context: http://r.789695.n4.nabble.com/Find-the-empty-element-in-a-factor-array-tp3238894p3238894.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] weighted x variables with glm
I have a glm regression (quasi-poisson) of log(mu) on x but I have varying degrees of confidence in the x values, and can attach a numerical weighting to each. Can anyone help me with suggestions of how to analysise this. Is there an R package that would help? Wendy [[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] Calculation of Covariance Matrix Calculation
Hi, Excuse me for asking this silly question. But I really couldn't understand why cov() and ccov() don't work for my calculation of covariance matrix. a - matrix(1:8, 2, 4) a [,1] [,2] [,3] [,4] [1,]1357 [2,]2468 ccov(a) Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular I also tried colume bind, but it still doesn't work. a1- a[,1] a2 - a[,2] a3- a[,3] a4 - a[,4] acomb - cbind(a1,a2,a3,a4) acomb a1 a2 a3 a4 [1,] 1 3 5 7 [2,] 2 4 6 8 ccov(acomb) Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular Yesterday, I used cov(), my function worked well. But today I ran the same code, it returned an error like: cov(td12) Error in solve.default(cov, ...) : system is computationally singular: reciprocal condition number = 1.97276e-24 In addition: Warning message: 'cov' is deprecated. Use 'ccov' instead. See help(Deprecated) I don't know what is wrong, and I appreciate you kind help! Thank you! Wendy [[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] Confusion of cov() and ccov() Function Error
On Mon, Jul 19, 2010 at 9:09 AM, Wendy Han wendyha...@gmail.com wrote: Hi, Excuse me for asking this silly question. But I really couldn't understand why cov() and ccov() don't work for my calculation of covariance matrix. a - matrix(1:8, 2, 4) a [,1] [,2] [,3] [,4] [1,]1357 [2,]2468 ccov(a) Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular I also tried colume bind, but it still doesn't work. a1- a[,1] a2 - a[,2] a3- a[,3] a4 - a[,4] acomb - cbind(a1,a2,a3,a4) acomb a1 a2 a3 a4 [1,] 1 3 5 7 [2,] 2 4 6 8 ccov(acomb) Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular Yesterday, I used cov(), my function worked well. But today I ran the same code, it returned an error like: cov(td12) Error in solve.default(cov, ...) : system is computationally singular: reciprocal condition number = 1.97276e-24 In addition: Warning message: 'cov' is deprecated. Use 'ccov' instead. See help(Deprecated) I don't know what is wrong, and I appreciate you kind help! Thank you! Wendy [[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] export results
Hi all, I am looping through a function for 100 time in the middle of my code, and I want to output the results from this function. Is there a way to write the results into a txt or csv fil? For example, I write the results from the first loop to the first column of a spreadsheet and the results from the second loop to the second coclumn of a spreadsheet etc. Thank you very much, Wendy -- View this message in context: http://n4.nabble.com/export-results-tp1568880p1568880.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] change email subscription
Dear R team, As this is a university email address with very small inbox limit, can I please change my R email subscription to another email address instead of this one? My new email address is wendy2.q...@gmail.com. I have change my email in my profile, but seems that does not change my subscription. Thank you. Wendy [[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] machine precision problem
Dear all, I am analysising a set of gene expression data using multiplicative Gaussian Kernel function. I calculated the kernels between two gene sets with 2 genes for each set. The kernels are less than 1, therefore the product of the kernels is out of the minimum precision in R. I wonder if there is a way to lowering the minimum double precision in R. I am using R version 2.10.1. Thank you in advance. Wendy -- View this message in context: http://n4.nabble.com/machine-precision-problem-tp1563732p1563732.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] coerce (list) object to type 'double'
Dear all, I am really new to R, and I have problem here. I searched around, but did not get a solution. I have a numetrix matrix (20 by 25) saved in .csv. I read it as sx-read.csv(sx.csv,header=F) Then I try to convert it to numeric using sx-as.numeric(sx) Error: (list) object cannot be coerced to type 'double' The class of sx is data.frame. I tried to unlist it as, s-unlist(sx), but when I look at the dimension, dim(s) NULL Can anyone tell me how should I load my data as a numeric matrix rather than data.frame, or how to convert the data.frame matrix into numeric? Thank you very much. Wendy -- View this message in context: http://n4.nabble.com/coerce-list-object-to-type-double-tp1562988p1562988.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] replicate matrix
Hi all, I have a matrix, for example [,1] [,2] [1,] 13 [2,] 46 I want to replicate the matrix twice and add an extra column at the end, which is [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 13 13 132 [2,] 46 46 465 I found 'rep' only works for vector. Does anyone know how to replicate a matrix, and append the matrix? Thank you in advance, Wendy -- View this message in context: http://n4.nabble.com/replicate-matrix-tp1563337p1563337.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.