[R] field names as function parameters
Hi, I am passing a data frame and field name to a function. I've figured out how I can create the formula based on the passed in field name, but I'm struggling to create a vector based in that field. for example if I hard code with the actual field name Y = df$Target, everything works fine. but if I use the passed in parameter name, it doesn't give me what I want, Y = df$mytarget Here is the function, # trying to pass field name to a function logistictest - function(df,mytarget) { #library for AUC calculation library(caTools) #build logistic model mytarget - deparse(substitute(mytarget)) myformula - paste(mytarget, ~ .) myformula - deparse(substitute(myformula)) logistic_reg - glm(myformula , data=df, family=binomial(link=logit)) print(model build OK) #score up scores - predict(logistic_reg, type=response, df) print(model scored OK) #calc AUC Y = df$mytarget auc - colAUC(scores,Y) print(auc calculated OK) } logistictest(df=trainset,mytarget=Target) [1] model build OK [1] model scored OK Error in as.vector(x, mode) : invalid 'mode' argument -- View this message in context: http://www.nabble.com/field-names-as-function-parameters-tp25838606p25838606.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] Matching Dates Closest without going over
Thanks Gabor. That was exactly what I was looking for. Ampy ampc wrote: Hi, I have 2 date vectors d1 and d2. d1 - structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309, 14278, 14247, 14216, 14185), class = Date) d2 - structure(c(14526, 14509, 14488, 14466, 14453, 14441, 14396, 14388, 14343, 14333, 14310, 14281), class = Date) I would like to create another dataframe with columns d1 and d2, where d1 is the original d1 and d2 is the max(d2) such that d1 d2. And NA's where not applicable. (See desired result below) Thanks, Ampy d1 2009-10-09 2009-09-08 2009-08-08 2009-07-08 2009-06-07 2009-05-07 2009-04-06 2009-03-06 2009-02-03 2009-01-03 2008-12-03 2008-11-02 d2 2009-10-09 2009-09-22 2009-09-01 2009-08-10 2009-07-28 2009-07-16 2009-06-01 2009-05-24 2009-04-09 2009-03-30 2009-03-07 2009-02-06 result: d1 d2 2009-10-09 2009-10-09 2009-09-08 2009-09-01 2009-08-08 2009-07-28 2009-07-08 2009-06-01 2009-06-07 2009-06-01 2009-05-07 2009-04-09 2009-04-06 2009-03-30 2009-03-06 2009-02-06 2009-02-03 NA 2009-01-03 NA 2008-12-03 NA 2008-11-02 NA -- View this message in context: http://www.nabble.com/Matching-Dates-Closest-without-going-over-tp25830902p25838149.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do I reverse the digits of a number
Hi All, Thanks for your help. I need to reverse the digits of a number (unknown lenght). Example 1234-4321 Tom -- View this message in context: http://www.nabble.com/How-do-I-reverse-the-digits-of-a-number-tp25838410p25838410.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] Manipulating Arrays
Manipulating Arrays Using the below data: df - structure(list(dim1 = structure(c(1L, 3L, 1L, 4L, 1L, 2L, 2L, 2L, 3L, 1L, 4L, 3L, 4L, 4L, 3L, 2L), .Label = c(a1, a2, a3, a4), class = factor), dim2 = structure(c(2L, 1L, 2L, 2L, 4L, 3L, 1L, 3L, 1L, 3L, 2L, 4L, 3L, 4L, 1L, 4L), .Label = c(b1, b2, b3, b4), class = factor), dim3 = structure(c(1L, 4L, 3L, 2L, 1L, 1L, 2L, 4L, 3L, 2L, 2L, 3L, 3L, 1L, 4L, 4L), .Label = c(c1, c2, c3, c4), class = factor), dim4 = structure(c(2L, 4L, 1L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 4L), .Label = c(d1, d2, d3, d4), class = factor), value = c(33L, 28L, 97L, 64L, 95L, 64L, 21L, 76L, 93L, 50L, 30L, 7L, 89L, 57L, 27L, 14L )), .Names = c(dim1, dim2, dim3, dim4, value), class = data.frame, row.names = c(NA, -16L)) library(reshape) arr - cast(df, dim1~dim2~dim3~dim4, sum) dim(arr) [1] 4 4 4 4 How do I manipulate this array? 1. Can I add an extra element in the first dimension using the existing dimensions? As in a dataframe? Such as (The below does not work) arr[5,,,] - arr[1,,,] * 2 + 1 Error in arr[5, , , ] - arr[1, , , ] * 2 + 1 : subscript out of bounds 2. How do I remove say the 2 element of the first dimension and have other elements re-arranged in the logical way i.e deleting arr[2,,,] means arr[3,,,] becomes arr[2,,,]; and arr[4,,,] becomes arr[3,,,] (again the below does not work) arr[2,,,] - NULL Error in arr[2, , , ] - NULL : number of items to replace is not a multiple of replacement length -- View this message in context: http://www.nabble.com/Manipulating-Arrays-tp25838608p25838608.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do you test if a number is in a list of numbers?
Hi, I want to subset a data frame if one of the variables matches any in a list. I could of course do something like this: subset(dataset, var == 1 | var == 2 | var ==3) but that's tedious. I tried varlist = c(1,2,3,4) subset(dataset, any(var == varlist)) but it doesn't work because 'any' doesn't go row-by-row and hence always returns TRUE. Is there any simple way to do this? Justin -- View this message in context: http://www.nabble.com/How-do-you-test-if-a-number-is-in-a-list-of-numbers--tp25840964p25840964.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] field names as function parameters
Hi, I think this is a case where you should use the ?[[ extraction operator rather than $, d = data.frame(a=1:3) mytarget = a d[[mytarget]] HTH, baptiste 2009/10/11 tdm ph...@philbrierley.com: Hi, I am passing a data frame and field name to a function. I've figured out how I can create the formula based on the passed in field name, but I'm struggling to create a vector based in that field. for example if I hard code with the actual field name Y = df$Target, everything works fine. but if I use the passed in parameter name, it doesn't give me what I want, Y = df$mytarget Here is the function, # trying to pass field name to a function logistictest - function(df,mytarget) { #library for AUC calculation library(caTools) #build logistic model mytarget - deparse(substitute(mytarget)) myformula - paste(mytarget, ~ .) myformula - deparse(substitute(myformula)) logistic_reg - glm(myformula , data=df, family=binomial(link=logit)) print(model build OK) #score up scores - predict(logistic_reg, type=response, df) print(model scored OK) #calc AUC Y = df$mytarget auc - colAUC(scores,Y) print(auc calculated OK) } logistictest(df=trainset,mytarget=Target) [1] model build OK [1] model scored OK Error in as.vector(x, mode) : invalid 'mode' argument -- View this message in context: http://www.nabble.com/field-names-as-function-parameters-tp25838606p25838606.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] How do you test if a number is in a list of numbers?
This is pretty standard. varList - 1:4 subData - subset(dataset, var %in% varList) Should do it. W. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of JustinNabble [justinmmcgr...@hotmail.com] Sent: 11 October 2009 16:13 To: r-help@r-project.org Subject: [R] How do you test if a number is in a list of numbers? Hi, I want to subset a data frame if one of the variables matches any in a list. I could of course do something like this: subset(dataset, var == 1 | var == 2 | var ==3) but that's tedious. I tried varlist = c(1,2,3,4) subset(dataset, any(var == varlist)) but it doesn't work because 'any' doesn't go row-by-row and hence always returns TRUE. Is there any simple way to do this? Justin -- View this message in context: http://www.nabble.com/How-do-you-test-if-a-number-is-in-a-list-of-numbers--tp25840964p25840964.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] field names as function parameters
Thanks, just the clue I needed, worked a treat. baptiste auguie-5 wrote: Hi, I think this is a case where you should use the ?[[ extraction operator rather than $, d = data.frame(a=1:3) mytarget = a d[[mytarget]] HTH, baptiste 2009/10/11 tdm ph...@philbrierley.com: Hi, I am passing a data frame and field name to a function. I've figured out how I can create the formula based on the passed in field name, but I'm struggling to create a vector based in that field. for example if I hard code with the actual field name Y = df$Target, everything works fine. but if I use the passed in parameter name, it doesn't give me what I want, Y = df$mytarget Here is the function, # trying to pass field name to a function logistictest - function(df,mytarget) { #library for AUC calculation library(caTools) #build logistic model mytarget - deparse(substitute(mytarget)) myformula - paste(mytarget, ~ .) myformula - deparse(substitute(myformula)) logistic_reg - glm(myformula , data=df, family=binomial(link=logit)) print(model build OK) #score up scores - predict(logistic_reg, type=response, df) print(model scored OK) #calc AUC Y = df$mytarget auc - colAUC(scores,Y) print(auc calculated OK) } logistictest(df=trainset,mytarget=Target) [1] model build OK [1] model scored OK Error in as.vector(x, mode) : invalid 'mode' argument -- View this message in context: http://www.nabble.com/field-names-as-function-parameters-tp25838606p25838606.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. -- View this message in context: http://www.nabble.com/field-names-as-function-parameters-tp25840951p25841450.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] Substituting the extracted coefficients into the formula, exctracted from the result of nls()
Thank you. I guess using predict() is probably closest to the R philosophy. All the best, Primož 2009/10/9 Henrique Dallazuanna www...@gmail.com: Try with predict: plot(x, y) lines(0:10, predict(yfit, list(x = 0:10))) 2009/10/9 Primoz PETERLIN primozz.peter...@gmail.com: Dear all, Here I come with another stupid question. Suppose I want to use nls() to fit a series of data (here modelled by generated points), then plot the points and the fitting curve. I figured out some way of doing it: x - runif(1:20, 0, 10) y - 0.1*x^2 - rep(3, length(x)) + rnorm(length(x), sd = 0.5) yfit - nls(y ~ a*x^2 + b*x + c, start = list(a = 1, b = 1, c = 1), trace = TRUE) plot(x, y) curve(coef(yfit)[1]*x^2 + coef(yfit)[2]*x + coef(yfit)[3], 0, 10, add = TRUE) However, this code is rather fortranesque, and most likely there exists a much more elegant way in R/S, something like abline() which exists for straight lines. Since both the formula and the coefficients are available as a result of nls() (here as formula(yfit) and coef(yfit)), I thought there ought to be a way something along the following lines: f - substitute(formula(yfit), as.list(coef(yfit))) curve(f, ...) However, this snippet of code doesn't work. Am I thinking into the correct direction at all? Thanks in advance. All the best, Primož -- Primož Peterlin, Inštitut za biofiziko, Med. fakulteta, Univerza v Ljubljani Lipičeva 2, SI-1000 Ljubljana, Slovenija. primoz.peter...@mf.uni-lj.si Tel +386-1-5437612, fax +386-1-4315127, http://biofiz.mf.uni-lj.si/~peterlin/ F8021D69 OpenPGP fingerprint: CB 6F F1 EE D9 67 E0 2F 0B 59 AF 0D 79 56 19 0F __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Primož Peterlin, Inštitut za biofiziko, Med. fakulteta, Univerza v Ljubljani Lipičeva 2, SI-1000 Ljubljana, Slovenija.primoz.peter...@mf.uni-lj.si Tel +386-1-5437612, fax +386-1-4315127, http://biofiz.mf.uni-lj.si/~peterlin/ F8021D69 OpenPGP fingerprint: CB 6F F1 EE D9 67 E0 2F 0B 59 AF 0D 79 56 19 0F __ 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] Decreasing Sort Error Message
Can anybody tell me how to fix this error? Thanks, Tom array_down = sort(sort_array,decreasing = 1) Error in sort(sort_array, decreasing = 1) : 'decreasing' must be a length-1 logical vector. -- View this message in context: http://www.nabble.com/Decreasing-Sort-Error-Message-tp25841678p25841678.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] Decreasing Sort Error Message
On 10/11/2009 10:55 AM, tom_p wrote: Can anybody tell me how to fix this error? Thanks, Tom 'decreasing' must be a length-1 logical vector. so either TRUE or FALSE array_down = sort(sort_array,decreasing = TRUE ) array_down = sort(sort_array,decreasing = 1) Error in sort(sort_array, decreasing = 1) : 'decreasing' must be a length-1 logical vector. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/BcPw : celebrating R commit #5 |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc `- http://tr.im/yw8E : New R package : sos __ 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] Manipulating Arrays
Hi, the abind package can help you with the first query, ## add values library(abind) arr - abind(arr,arr[1,,,] * 2 + 1,along=1) dim(arr) as for the second, maybe you can use negative indexing, ## remove values arr - arr[-2,,,] HTH, baptiste 2009/10/11 ampc ampc2...@gmail.com: Manipulating Arrays Using the below data: df - structure(list(dim1 = structure(c(1L, 3L, 1L, 4L, 1L, 2L, 2L, 2L, 3L, 1L, 4L, 3L, 4L, 4L, 3L, 2L), .Label = c(a1, a2, a3, a4), class = factor), dim2 = structure(c(2L, 1L, 2L, 2L, 4L, 3L, 1L, 3L, 1L, 3L, 2L, 4L, 3L, 4L, 1L, 4L), .Label = c(b1, b2, b3, b4), class = factor), dim3 = structure(c(1L, 4L, 3L, 2L, 1L, 1L, 2L, 4L, 3L, 2L, 2L, 3L, 3L, 1L, 4L, 4L), .Label = c(c1, c2, c3, c4), class = factor), dim4 = structure(c(2L, 4L, 1L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 4L), .Label = c(d1, d2, d3, d4), class = factor), value = c(33L, 28L, 97L, 64L, 95L, 64L, 21L, 76L, 93L, 50L, 30L, 7L, 89L, 57L, 27L, 14L )), .Names = c(dim1, dim2, dim3, dim4, value), class = data.frame, row.names = c(NA, -16L)) library(reshape) arr - cast(df, dim1~dim2~dim3~dim4, sum) dim(arr) [1] 4 4 4 4 How do I manipulate this array? 1. Can I add an extra element in the first dimension using the existing dimensions? As in a dataframe? Such as (The below does not work) arr[5,,,] - arr[1,,,] * 2 + 1 Error in arr[5, , , ] - arr[1, , , ] * 2 + 1 : subscript out of bounds 2. How do I remove say the 2 element of the first dimension and have other elements re-arranged in the logical way i.e deleting arr[2,,,] means arr[3,,,] becomes arr[2,,,]; and arr[4,,,] becomes arr[3,,,] (again the below does not work) arr[2,,,] - NULL Error in arr[2, , , ] - NULL : number of items to replace is not a multiple of replacement length -- View this message in context: http://www.nabble.com/Manipulating-Arrays-tp25838608p25838608.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] row selection
On Thu, 2009-10-08 at 16:14 -0400, Ashta wrote: Hi all, I have a matrix named x with N by C I want to select every 5 th rrow from matrix x I used the following code n- nrow(x) for(i in 1: n){ + b - a[i+5,] b } Error: subscript out of bounds Can any body point out the problem? Hi Ashta, If I understand your request you need select row 5,10,15, ... In this case you can use this script: x[1:nrow(n)%%5==0] -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil __ 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] permutations
jholtman wrote: try this to get the column output: cat(x, sep='\n', file='/tempxx.txt') Thanks for your answer. I've tried the command cat , but give me this error: x-permn(c(2,3,5,7)) cat(x, file=/my_path/filename.txt,\n) Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' -- View this message in context: http://www.nabble.com/permutations-tp25834463p25842437.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] barchart
Hi,In Lattice graphs, can I use reorder function in a barchart as in the case of dotchart? Or it can be used only with dotcharts? Thanks Chetty Professor of Family Medicine Boston University Tel: 617-414-6221, Fax:617-414-3345 emails: chett...@gmail.com,vche...@bu.edu [[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 do I reverse the digits of a number
Try this: library(tcltk) as.numeric(tcl(string, reverse, 123)) [1] 321 On Sat, Oct 10, 2009 at 5:37 PM, tom_p t.p...@hotmail.com wrote: Hi All, Thanks for your help. I need to reverse the digits of a number (unknown lenght). Example 1234-4321 Tom -- View this message in context: http://www.nabble.com/How-do-I-reverse-the-digits-of-a-number-tp25838410p25838410.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] How do I reverse the digits of a number
On Sun, Oct 11, 2009 at 12:53 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: library(tcltk) as.numeric(tcl(string, reverse, 123)) [1] 321 The bit where the original poster said 'unknown length' worried me: as.numeric(tcl(string, reverse, 12377656534)) [1] 0.4356568 as.numeric(paste(rev(strsplit(as.character(1234567890123727723),)[[1]]),collapse=)) [1] 6.167273e+18 As well as the use of the word 'number' - both solutions give NA for negative integers and various things for decimals... Just a bit of Sunday morning pedantry for you :) Barry __ 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] Creating a Clustered-Stacked Column Chart
zhijie zhang wrote: Thanks for your ideas and suggestions. I need to point out that most of us will create the Clustered-Stacked Column Chart in the matrix layout as David gave above, but here i hope to display the graph side by side as the example in the link http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html, which may be not a good method to display the information. Actually, i browsed the lattice package and re-run the examples in its help before posting this question. As John said above, I don't think I've seen an R version, probably because the technique is not very good for displaying data.. Following Peter's suggestion, i browsed the layout= argument in the link http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/lattice/html/xyplot.html and tried it, but cannot successfully get the correct graph. library(lattice) barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived)) barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived),layout=c(2,1)) #missed the children's graph barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived),layout=c(1,2)) #missed the children's graph Thanks a lot. Didn't miss anything. It just produced two pages. Try it with plot recording turned on. This should be close to what you want: barchart(Titanic, scales = list(x = free), layout = c(4,1), horizontal = FALSE, auto.key = list(title = Survived)) -Peter Ehlers 2009/10/10 Peter Ehlers ehl...@ucalgary.ca I think you're missing the point. David _did_ show you how to create a graph showing 4 clusters of stacked barcharts. If you want them side-by-side instead of in the matrix layout David gave, use the layout= argument. -Peter Ehlers zhijie zhang wrote: Hi David, Your codes are for stacked chart. Actually, i hope to Create a Clustered-Stacked Column Chart, which means that a chart will combine the traits of stacked chart and clustered chart, see the example in the page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html. Thanks. 2009/10/10 David Winsemius dwinsem...@comcast.net library(lattice) barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived)) Or if you prefer vertical: barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE) There are adjustments available to the space between bars. barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE, box.ratio=100) On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote: Thanks a lot. Maybe someone else has the method to solve that. 2009/10/9 John Kane jrkrid...@yahoo.ca I don't think I've seen an R version, probably because the technique is not very good for displaying data. Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an alternative method of displaying the data using lattice. --- On Fri, 10/9/09, zhijie zhang rusers...@gmail.com wrote: From: zhijie zhang rusers...@gmail.com Subject: [R] Creating a Clustered-Stacked Column Chart To: r-h...@stat.math.ethz.ch Received: Friday, October 9, 2009, 5:31 AM Hi all, In R, is there some functions or ways to create a Clustered-Stacked Column Chart as the example in the following page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html? I have browsed the R Graph Gallery ( http://addictedtor.free.fr/graphiques/) and searched the R site, and didnot find an appropriate method to do it. Anybody has met this problem before? Thanks a lot. [[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.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/ [[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.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible
Re: [R] lattice auto.key drop unused levels
Jacob Wegelin wrote: On Sat, Oct 10, 2009 at 8:51 PM, Peter Ehlers ehl...@ucalgary.ca wrote: The key will show the levels of the 'groups' factor. So you will have to ensure that the factor fed to groups has the levels that you want displayed. ?xyplot explicitly states that drop.unused.levels will NOT do that for you. So the answer seems to be that there is no way to drop the levels without bypassing the subset argument. The following creates the desired effect: xyplot(yield~nitro, data=Oats[Oats$Block==I | Oats$Block==II , ] , group=Block [, drop=T], auto.key=T) This gives you the desired effect because you are manipulating the data set used by xyplot to contain a variable 'Block' that has 6 levels only 2 of which are represented. The way that you're specifying the 'groups' argument then drops the unused levels. This is equivalent to doing the following before calling xyplot(): data.to.plot - subset(Oats, Block %in% c(I, II)) (at which point 'Block' still has 6 levels), followed by grouping.factor - data.to.plot$Block[,drop = TRUE] which will drop the unused levels of Block in grouping.factor. Then xyplot(yield ~ nitro, data = data.to.plot, groups = grouping.factor, auto.key = TRUE) whereas dropping levels in the group argument does not create the desired effect xyplot(yield~nitro, subset=(Block==I | Block==II), data=Oats, group=Block [, drop=T], auto.key=T) Yes, here the data set Oats still has all 72 observations and all 6 levels of 'Block' are represented. Block[,drop = TRUE] has no effect because there are no levels to drop. I think the key thing is to realize that 'subset' in xyplot does nothing to the data other than to plot only those rows that are specified by the subset argument. It does not alter the data. Personally, I usually manipulate the data before passing it to plotting functions. Cheers, Peter Ehlers Jacob Wegelin -Peter Ehlers Jacob Wegelin wrote: The following code produces a legend (key) that mentions the unused levels of Block. library(MEMSS) xyplot(yield~nitro, subset=(Block==I | Block==II), data=Oats, group=Block, auto.key=T) and adding drop.unused.levels=T does not fix it. And in fact even the following does not solve the problem: xyplot(yield~nitro, data=Oats[Oats$Block==I | Oats$Block==II,], group=Block, auto.key=T) The following workaround solves it, but seems inelegant: junk-Oats[Oats$Block==I | Oats$Block==II,] junk$Block-factor(as.character(junk$Block)) xyplot(yield~nitro, group=Block, data=junk, auto.key=T) What is the elegant or proper R thinking way to do this? That is, I want to get a key that only mentions the levels of Block that are used in the plot. __ 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] spectral analysis
Dear all, I am searching the period of a time series usering R. Is there some lag window functions in R? Could you give me some books about spectral analysis usering R? best wishes, Wang [[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 do I reverse the digits of a number
On Sun, Oct 11, 2009 at 8:09 AM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Sun, Oct 11, 2009 at 12:53 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: library(tcltk) as.numeric(tcl(string, reverse, 123)) [1] 321 The bit where the original poster said 'unknown length' worried me: as.numeric(tcl(string, reverse, 12377656534)) [1] 0.4356568 If you really are dealing with numbers this long pass them as strings: as.numeric(tcl(string, reverse, format(12377656534))) [1] 43565677321 At some length this will fail too but one can use just strings: as.character(tcl(string, reverse, 12377656534)) [1] 43565677321 __ 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] spectral analysis
On Oct 11, 2009, at 8:38 AM, sdlywjl666 wrote: Dear all, I am searching the period of a time series usering R. Is there some lag window functions in R? ?lag Could you give me some books about spectral analysis usering R? best wishes, Wang You might try being more specific. The easy, quick answer is yes: http://www.amazon.com/s/ref=nb_ss?url=search-alias%3Dstripbooksfield-keywords=time+series+in+rx=17y=17 The original book about R , known in these parts as MASS, had quite a bit. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Active learning and logistic regression.
Hi, I have binary file with a set of tunable real parameters. Upon execution the file returns 0 or 1 with some probability. (therefore (nonlinear) logistic regression) I need to find a set of parameters for which the probability of 1 is high. I would like to create program that would repeatably execute my file with different parameters, get 0,1 response after each execution (therefore active learning) and build a model of the underlying probability distribution. How to aproach this problem with R? Are there libraries, scripts that I could start with? Thanks Lukasz Lew __ 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] Ubuntu, Revolutions, R
Andrew Choens andy.choens at gmail.com writes: I am interested in hearing from members of the community, REvolution Computing employees/supporters (although please ID yourself as such) and most anyone else. I can see what they say on their website, but I'm interested in getting other opinions too. Thanks! Ubuntu is a commercial distribution, for loose definitions of commercial. Why shouldn't they cut a deal with Revolution, who is doing a very similar thing? If you want something closer to the ideal of volunteer-driven free as in beer and speech, you'll need to stick with Debian. Canonical and Revolution have very similar business models. And they just happen to have similar relationships to volunteer-driven development in Debian and R-Core. -tony AJ Rossini blindgl...@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] Plotting groupedData objects by levels of a factor
Hi, I'm trying to plot a grouped data object for modelling maximum branch size by distance from stem apex: MAXBRD.group - groupedData(MAXBRD ~ Dtop | Type/Site/Tree, inner=~Status, data=MAXBRD.data). The following code produces a plot of MAXBRD ~ Dtop for each site type: plot(MAXBRD.group, collapse=1, display=1, aspect=1.2, pch=20, inner=~1, main=MAXBRD with Distance from Stem Apex, xlab=Distance from stem apex (m), ylab=Max Branch Diameter (mm)) But I would like the plot to show different colour points for Live and Dead branches (variable name =Status). At the moment the plot does not distinguish between branches of different status. I can draw the plot using xyplot but then the panels aren't grouped according to the structure of the grouped data object, and auto.key gives different points to those in the plot. Can anyone help with this? Thanks in advance. Dave Auty + The Forestry Commission's computer systems may be monitored and communications carried out on them recorded, to secure the effective operation of the system and for other lawful purposes. + The original of this email was scanned for viruses by the Government Secure Intranet (GSi) virus scanning service supplied exclusively by Cable Wireless in partnership with MessageLabs. On leaving the GSi this email was certified virus-free [[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] Display more than one plot
Hey Joris! Thanks, I can do that now, you've been a great help. JorisMeys wrote: Just saw I did something stupid. Both examples create a 2 by 2 grid in your graph window, so you'll be able to plot 4 graphs in that window. If you plot only 2 graphs, the lower half of the window will be empty still. Just check the helpfiles and experiment a bit to get a grip of how to get which graph where. It's pretty straight forward. Kind regards Joris On Sun, Oct 11, 2009 at 12:50 AM, joris meys jorism...@gmail.com wrote: Hi Emkay, If you want to look at different plots together, you can also plot them side by side in the same plot window. You can specify this using for example: par(mfcol=c(2,2)) ( see ?par and check mfrow and mfcol) or layout(matrix(1:4,2,2)) (see ?layout and ?matrix) eg : x - c(1,2,3,4,5,6,7,8,9,0) y - c(1,2,3,4,5,6,7,8,9,0) z - c(8,7,6,5,4,3,2,1,0,9) par(mfcol=c(2,2)) plot(x,y) plot(x,z) Kind regards Joris On Sat, Oct 10, 2009 at 4:51 AM, emkayenne michaelkristoffern...@gmail.com wrote: Nobody? :-( emkayenne wrote: Hello, I'm pretty new to R and I am having a hrd time getting a grip. Just a question: can someone tell me how to have more than one graphics windown open at the same time? I want to look at some plote at the same time..., how is this done? If someone has a suggestion for a (good) introductory guide to R, much appreciated, but not the manual..., this one I do have. :confused: Thank you for your help guys, Emkay -- View this message in context: http://www.nabble.com/Display-more-than-one-plot-tp25829214p25830526.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. -- View this message in context: http://www.nabble.com/Display-more-than-one-plot-tp25829214p25843211.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] DBI fetch argument ellipses?
Sorry, this is an R newbie question: I have managed to sucessfully do some of the basic access of a MySQL data base with R but I have a question about the 'fetch' function. The documentation refers to fetch(res, n, ...) but never fully describes the ellipses (...) nor provides examples of what the field would contain. This is a problem in both the 'help(fetch)' as well as the PDF documentation. An expanded comment/example would be helpful. Thank-you. PS: this also seems to be a problem with some other function documentation. -- The whole religious complexion of the modern world is due to the absence from Jerusalem of a lunatic asylum. -- Havelock Ellis (1859-1939) British psychologist __ 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] Error in family$family : $ operator is invalid for atomic vectors
Dear List, I'm having problem with an exercise from The R book (M.J. Crawley) on page 567. Here is the entire code upto the point where I get an error. data(UCBAdmissions) x - aperm(UCBAdmissions, c(2, 1, 3)) names(dimnames(x)) - c(Sex, Admit?, Department) ftable(x) fourfoldplot(x, margin = 2) dept-gl(6,4) sex-gl(2,1,24) admit-gl(2,2,24) model1-glm(as.vector(x) ~dept*sex*admit,poisson) This last line returns: Error in family$family : $ operator is invalid for atomic vectors I've searched older posts but found nothing that would help resolve my problem. Has anyone encountered anything similar and/or knows a fix? Cheers, Roman [[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] permutations
Hi Eiger, Here a suggestion to get the output in the format you want: # Package, data and path require(combinat) x - do.call(rbind,permn(c(23,46,70,71,89))) f - C:/permutations.txt # Original output write.table(x, f, col.names = F, row.names = F) # Transposed output write.table(t(x), C:/transpermutations.txt, col.names = F, row.names = F) HTH, Jorge On Sun, Oct 11, 2009 at 7:04 AM, Eiger wrote: jholtman wrote: try this to get the column output: cat(x, sep='\n', file='/tempxx.txt') Thanks for your answer. I've tried the command cat , but give me this error: x-permn(c(2,3,5,7)) cat(x, file=/my_path/filename.txt,\n) Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' -- View this message in context: http://www.nabble.com/permutations-tp25834463p25842437.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. [[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] Error in family$family : $ operator is invalid for atomic vectors
On Sun, Oct 11, 2009 at 4:54 PM, romunov romu...@gmail.com wrote: Dear List, I'm having problem with an exercise from The R book (M.J. Crawley) on page 567. Here is the entire code upto the point where I get an error. data(UCBAdmissions) x - aperm(UCBAdmissions, c(2, 1, 3)) names(dimnames(x)) - c(Sex, Admit?, Department) ftable(x) fourfoldplot(x, margin = 2) dept-gl(6,4) sex-gl(2,1,24) admit-gl(2,2,24) model1-glm(as.vector(x) ~dept*sex*admit,poisson) This last line returns: Error in family$family : $ operator is invalid for atomic vectors I've searched older posts but found nothing that would help resolve my problem. Has anyone encountered anything similar and/or knows a fix? Works for me: model1-glm(as.vector(x) ~dept*sex*admit,poisson) model1 Call: glm(formula = as.vector(x) ~ dept * sex * admit, family = poisson) Coefficients: (Intercept) dept2 dept3 dept4 6.23832 -0.37186 -1.45083 -1.31107 [etc] What's your version: version _ platform i486-pc-linux-gnu arch i486 os linux-gnu system i486, linux-gnu status major 2 minor 9.2 year 2009 month 08 day24 svn rev49384 language R version.string R version 2.9.2 (2009-08-24) Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in family$family : $ operator is invalid for atomic vectors
Hi Romain, It works for me: model1 - glm(as.vector(x) ~dept*sex*admit,poisson) model1 Call: glm(formula = as.vector(x) ~ dept * sex * admit, family = poisson) Coefficients: (Intercept) dept2 dept3 dept4 dept5 6.23832 -0.37186 -1.45083 -1.31107 -2.26803 dept6 sex2 admit2 dept2:sex2 dept3:sex2 [trimmed] Here is my sessionInfo(): R version 2.9.2 RC (2009-08-23 r49375) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-25 combinat_0.0-6 loaded via a namespace (and not attached): [1] grid_2.9.0 tools_2.9.0 HTH, Jorge On Sun, Oct 11, 2009 at 11:54 AM, romunov wrote: Dear List, I'm having problem with an exercise from The R book (M.J. Crawley) on page 567. Here is the entire code upto the point where I get an error. data(UCBAdmissions) x - aperm(UCBAdmissions, c(2, 1, 3)) names(dimnames(x)) - c(Sex, Admit?, Department) ftable(x) fourfoldplot(x, margin = 2) dept-gl(6,4) sex-gl(2,1,24) admit-gl(2,2,24) model1-glm(as.vector(x) ~dept*sex*admit,poisson) This last line returns: Error in family$family : $ operator is invalid for atomic vectors I've searched older posts but found nothing that would help resolve my problem. Has anyone encountered anything similar and/or knows a fix? Cheers, Roman [[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] many weighted means: is there a simpler way?
On Sun, 11 Oct 2009, Ozan Bak???~_ wrote: Hi R-users, I would like to calculate weighted mean of several variables by two factors where the weight vector is the same for all variables. Below, there is a simple example where I have only two variables: v1,v2 both weighted by wt and my factors are gender and year. set.seed(1) df - data.frame(gender = rep(c(M, F),each = 5), year = rep(c(1999, 2000), 5), v1 = rnorm(10,10), v2 = rnorm(10,6), wt = runif(10)) df g - function(x) weighted.mean(x[, 1], x[, 2]) by(df[,c(v1,wt)],df[,c(year,gender)],g) I can use as above by command for each variable (v1,v2) separately but I wonder if there is some simpler way that yields a table/data frame of weigted means for all vis where i=1...N. This is R; There are lots of ways. Here is one: lm( cbind( v1, v2 ) ~ 0 + gender:factor(year), df, weight=wt) Call: lm(formula = cbind(v1, v2) ~ 0 + gender:factor(year), data = df, weights = wt) Coefficients: v1 v2 genderF:factor(year)1999 10.573 6.795 genderM:factor(year)1999 9.534 6.633 genderF:factor(year)2000 9.741 6.422 genderM:factor(year)2000 10.834 5.190 HTH, Chuck Thank you very much, ozan [[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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ 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] Social networking around R
Hi R users, I'd be interested in what R users think about social networking around all things R. For this, I've set up a social network @ www.rstuff.socialgo.comand it would be great if you could post your comments on the forum created for this discussion. The News section has feeds from some of the R related blogs I've been following. I'm hoping for a central resource that keeps tracks of R related information, news, blogs, events and community relevant information. In any case, its usefulness will decide its evolution Thank you for your time, Regards Harsh [[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] Social networking around R
Hi, I'm new to R to and think it might be a good idea... who knows? I was lurking in the R channel on freenode some days back and someone was complaining about how no one ever talks there... Anyway, signing up now... Cheers, Kenny On Mon, Oct 12, 2009 at 1:10 AM, Harsh singhal...@gmail.com wrote: Hi R users, I'd be interested in what R users think about social networking around all things R. For this, I've set up a social network @ www.rstuff.socialgo.comand it would be great if you could post your comments on the forum created for this discussion. The News section has feeds from some of the R related blogs I've been following. I'm hoping for a central resource that keeps tracks of R related information, news, blogs, events and community relevant information. In any case, its usefulness will decide its evolution Thank you for your time, Regards Harsh [[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. -- - A mental model is good. I change mine all the time. [[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] Why H1=1? (H's the hat matrix)
Suppose I have the following hat matrix: H=X(X'X)^{-1}X' X is a n by p matrix, where n = p and X_{i,1} = 1 I'm wondering why H1 = 1. (Here, 1 is column vector, whose each element is the number 1) Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why H1=1? (H's the hat matrix)
H projects vectors onto the range of X so any vector already in the range of X gets projected onto itself. On Sun, Oct 11, 2009 at 2:03 PM, Peng Yu pengyu...@gmail.com wrote: Suppose I have the following hat matrix: H=X(X'X)^{-1}X' X is a n by p matrix, where n = p and X_{i,1} = 1 I'm wondering why H1 = 1. (Here, 1 is column vector, whose each element is the number 1) Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Why H1=1? (H's the hat matrix)
Dear Peng, This seems a curious question to pose on r-help: The vector 1 is the first column of X, and hence lies in the subspace spanned by the columns of X. H projects any vector orthogonally onto the subspace spanned by X. Thus, if a vector, such as 1, lies in this subspace, it's projected onto itself. Regards, John -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu Sent: October-11-09 2:03 PM To: r-h...@stat.math.ethz.ch Subject: [R] Why H1=1? (H's the hat matrix) Suppose I have the following hat matrix: H=X(X'X)^{-1}X' X is a n by p matrix, where n = p and X_{i,1} = 1 I'm wondering why H1 = 1. (Here, 1 is column vector, whose each element is the number 1) Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Why H1=1? (H's the hat matrix)
Another, less geometric, way to think about this: The fitted response for a linear model is a weighted average of the observed responses. The i-th row of the hat matrix list the coefficients of the average for the i-th fitted value. These values sum to 1 for each row, and so H %*% 1=1. Cheers... - Simon Bonner Post-Doctoral Fellow Department of Statistics, UBC www.simon.bonners.ca On Sun, 2009-10-11 at 14:09 -0400, Gabor Grothendieck wrote: H projects vectors onto the range of X so any vector already in the range of X gets projected onto itself. On Sun, Oct 11, 2009 at 2:03 PM, Peng Yu pengyu...@gmail.com wrote: Suppose I have the following hat matrix: H=X(X'X)^{-1}X' X is a n by p matrix, where n = p and X_{i,1} = 1 I'm wondering why H1 = 1. (Here, 1 is column vector, whose each element is the number 1) Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Social networking around R
Harsh-7 wrote: Hi R users, I'd be interested in what R users think about social networking around all things R. For this, I've set up a social network @ www.rstuff.socialgo.comand it would be great if you could post your comments on the forum created for this discussion. Could you provide a complete URL. I'm getting a 404 not found. Thanks. -- View this message in context: http://www.nabble.com/Social-networking-around-R-tp25845449p25846415.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in family$family : $ operator is invalid for atomic vectors
Thank you Jorge and Barry for your input. I've fiddled around a bit and as a result, am even more confused. If I start R console via Notepad++ (I use Npp2R) and execute the model1, it goes through just fine. Here is the sessionInfo() for this working session: sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.9.2 And if I run R normally, via an icon from the desktop (Rgui.exe) it gives the aforementioned error. Here is the sessionInfo() for non-working session. Is it possible that grid, reshape, plyr, ggplot2 and proto could be causing this? If so, how can I prevent them from loading automatically or unloading from a live session? sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets grid methods [8] base other attached packages: [1] reshape_0.8.3 plyr_0.1.9proto_0.3-8 loaded via a namespace (and not attached): [1] ggplot2_0.8.3 Cheers, Roman On Sun, Oct 11, 2009 at 6:32 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Hi Romain, It works for me: model1 - glm(as.vector(x) ~dept*sex*admit,poisson) model1 Call: glm(formula = as.vector(x) ~ dept * sex * admit, family = poisson) Coefficients: (Intercept) dept2 dept3 dept4 dept5 6.23832 -0.37186 -1.45083 -1.31107 -2.26803 dept6 sex2 admit2 dept2:sex2 dept3:sex2 [trimmed] Here is my sessionInfo(): R version 2.9.2 RC (2009-08-23 r49375) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-25 combinat_0.0-6 loaded via a namespace (and not attached): [1] grid_2.9.0 tools_2.9.0 HTH, Jorge On Sun, Oct 11, 2009 at 11:54 AM, romunov wrote: Dear List, I'm having problem with an exercise from The R book (M.J. Crawley) on page 567. Here is the entire code upto the point where I get an error. data(UCBAdmissions) x - aperm(UCBAdmissions, c(2, 1, 3)) names(dimnames(x)) - c(Sex, Admit?, Department) ftable(x) fourfoldplot(x, margin = 2) dept-gl(6,4) sex-gl(2,1,24) admit-gl(2,2,24) model1-glm(as.vector(x) ~dept*sex*admit,poisson) This last line returns: Error in family$family : $ operator is invalid for atomic vectors I've searched older posts but found nothing that would help resolve my problem. Has anyone encountered anything similar and/or knows a fix? Cheers, Roman [[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] Manipulating Arrays
Thanks baptiste. Works as expected. ampy ampc wrote: Manipulating Arrays Using the below data: df - structure(list(dim1 = structure(c(1L, 3L, 1L, 4L, 1L, 2L, 2L, 2L, 3L, 1L, 4L, 3L, 4L, 4L, 3L, 2L), .Label = c(a1, a2, a3, a4), class = factor), dim2 = structure(c(2L, 1L, 2L, 2L, 4L, 3L, 1L, 3L, 1L, 3L, 2L, 4L, 3L, 4L, 1L, 4L), .Label = c(b1, b2, b3, b4), class = factor), dim3 = structure(c(1L, 4L, 3L, 2L, 1L, 1L, 2L, 4L, 3L, 2L, 2L, 3L, 3L, 1L, 4L, 4L), .Label = c(c1, c2, c3, c4), class = factor), dim4 = structure(c(2L, 4L, 1L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 4L), .Label = c(d1, d2, d3, d4), class = factor), value = c(33L, 28L, 97L, 64L, 95L, 64L, 21L, 76L, 93L, 50L, 30L, 7L, 89L, 57L, 27L, 14L )), .Names = c(dim1, dim2, dim3, dim4, value), class = data.frame, row.names = c(NA, -16L)) library(reshape) arr - cast(df, dim1~dim2~dim3~dim4, sum) dim(arr) [1] 4 4 4 4 How do I manipulate this array? 1. Can I add an extra element in the first dimension using the existing dimensions? As in a dataframe? Such as (The below does not work) arr[5,,,] - arr[1,,,] * 2 + 1 Error in arr[5, , , ] - arr[1, , , ] * 2 + 1 : subscript out of bounds 2. How do I remove say the 2 element of the first dimension and have other elements re-arranged in the logical way i.e deleting arr[2,,,] means arr[3,,,] becomes arr[2,,,]; and arr[4,,,] becomes arr[3,,,] (again the below does not work) arr[2,,,] - NULL Error in arr[2, , , ] - NULL : number of items to replace is not a multiple of replacement length -- View this message in context: http://www.nabble.com/Manipulating-Arrays-tp25838608p25846594.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in family$family : $ operator is invalid for atomic vectors
Check to see if you have an old workspace being loaded. You might have an object called 'family' which you might need to remove. --sundar On Oct 11, 2009 12:15 PM, romunov romu...@gmail.com wrote: Thank you Jorge and Barry for your input. I've fiddled around a bit and as a result, am even more confused. If I start R console via Notepad++ (I use Npp2R) and execute the model1, it goes through just fine. Here is the sessionInfo() for this working session: sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.9.2 And if I run R normally, via an icon from the desktop (Rgui.exe) it gives the aforementioned error. Here is the sessionInfo() for non-working session. Is it possible that grid, reshape, plyr, ggplot2 and proto could be causing this? If so, how can I prevent them from loading automatically or unloading from a live session? sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets grid methods [8] base other attached packages: [1] reshape_0.8.3 plyr_0.1.9proto_0.3-8 loaded via a namespace (and not attached): [1] ggplot2_0.8.3 Cheers, Roman On Sun, Oct 11, 2009 at 6:32 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Hi Romain, It works for me: model1 - glm(as.vector(x) ~dept*sex*admit,poisson) model1 ... [[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] Why H1=1? (H's the hat matrix)
Dear Simon, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Simon Bonner Sent: October-11-09 2:33 PM To: Peng Yu Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] Why H1=1? (H's the hat matrix) Another, less geometric, way to think about this: The fitted response for a linear model is a weighted average of the observed responses. The i-th row of the hat matrix list the coefficients of the average for the i-th fitted value. These values sum to 1 for each row, and so H %*% 1=1. That's true if there's a constant column in X, or more generally if the 1 vector lies in the subspace spanned by the columns of X, but not in general. Best, John Cheers... - Simon Bonner Post-Doctoral Fellow Department of Statistics, UBC www.simon.bonners.ca On Sun, 2009-10-11 at 14:09 -0400, Gabor Grothendieck wrote: H projects vectors onto the range of X so any vector already in the range of X gets projected onto itself. On Sun, Oct 11, 2009 at 2:03 PM, Peng Yu pengyu...@gmail.com wrote: Suppose I have the following hat matrix: H=X(X'X)^{-1}X' X is a n by p matrix, where n = p and X_{i,1} = 1 I'm wondering why H1 = 1. (Here, 1 is column vector, whose each element is the number 1) Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Error in family$family : $ operator is invalid for atomic vectors
Hello Sundar, I checked the ls() and it was full of something (something that I should have removed long ago but was not diligent enough). I have cleared the list (via rm(list=ls()) and the glm function works fine now. Cheers, Roman On Sun, Oct 11, 2009 at 9:21 PM, Sundar Dorai-Raj sdorai...@gmail.comwrote: Check to see if you have an old workspace being loaded. You might have an object called 'family' which you might need to remove. --sundar On Oct 11, 2009 12:15 PM, romunov romu...@gmail.com wrote: Thank you Jorge and Barry for your input. I've fiddled around a bit and as a result, am even more confused. If I start R console via Notepad++ (I use Npp2R) and execute the model1, it goes through just fine. Here is the sessionInfo() for this working session: sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.9.2 And if I run R normally, via an icon from the desktop (Rgui.exe) it gives the aforementioned error. Here is the sessionInfo() for non-working session. Is it possible that grid, reshape, plyr, ggplot2 and proto could be causing this? If so, how can I prevent them from loading automatically or unloading from a live session? sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250 attached base packages: [1] stats graphics grDevices utils datasets grid methods [8] base other attached packages: [1] reshape_0.8.3 plyr_0.1.9proto_0.3-8 loaded via a namespace (and not attached): [1] ggplot2_0.8.3 Cheers, Roman On Sun, Oct 11, 2009 at 6:32 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Hi Romain, It works for me: model1 - glm(as.vector(x) ~dept*sex*admit,poisson) model1 ... [[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] Saving Seed In a Lopp
I'm trying to save the random seed in a for loop. How can one go about doing that and preserving the seed for the next session. [[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] About finding NA values sources
Hi Are you one of my 380 students? If so, please contact me directly about any difficulties you are having with assignment work. Sending questions via R-help like this is inefficient because there is a chance that I might not spot it. At the very least, you should declare to all of the kind volunteers on this list that your question relates to coursework. Paul p.s. that also applies to the question you asked about lattice last week! Rene wrote: Dear All, In R, is there a way (or a function) I can quickly check whether all the NA values in one new created numerical variable happened are because of nbsp; or something else in the original dataset? And how can we easily group these NAs separately based on different reason (e.g. some NA are because of nbsp; , some are because of there are extra text inside, etc). Thanks heaps. Rene. [[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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ 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] Social networking around R
On Sun, Oct 11, 2009 at 7:51 PM, HBaize hba...@buttecounty.net wrote: Harsh-7 wrote: Hi R users, I'd be interested in what R users think about social networking around all things R. For this, I've set up a social network @ www.rstuff.socialgo.comand it would be great if you could post your comments on the forum created for this discussion. Could you provide a complete URL. I'm getting a 404 not found. http://www.rstuff.socialgo.com/ - original post had a space missing between 'com' and 'and'. Or your local DNS hasn't sorted itself out yet if this is a new name, but it should Barry __ 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] Saving Seed In a Lopp
Hey Galois (?), See the help file for set.seed() (help(set.seed)). In short, the current seed is stored in the variable .Random.seed. You can save the seed with: myseed - .Random.seed Hope that helps, Simon - Simon Bonner Post-Doctoral Fellow Department of Statistics, UBC www.simon.bonners.ca On Sun, 2009-10-11 at 15:33 -0400, Galois Theory wrote: I'm trying to save the random seed in a for loop. How can one go about doing that and preserving the seed for the next session. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Random number
Hi All, I have the matrix called 'X' with 200 rows and 12 variables. I want to create 2 new variables (V1 and V2) based on random number generator p1-rnorm(200. mean=0, std=1) p2-rnorm(200. mean=0, std=1) x - cbind(x, v1=ifelse(x[,'p1'] 0.4, 1, 0), v2=ifelse(x[,'p2'] 0.6, 0, 1)) I found the following error message *Error: unexpected symbol in p1-rnorm(200. mean Any 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] Random number
Hi Ashta, On Sun, Oct 11, 2009 at 4:06 PM, Ashta wrote: Hi All, I have the matrix called 'X' with 200 rows and 12 variables. I want to create 2 new variables (V1 and V2) based on random number generator p1-rnorm(200. mean=0, std=1) p2-rnorm(200. mean=0, std=1) ^^^ You are using . instead of ,. HTH, Jorge x - cbind(x, v1=ifelse(x[,'p1'] 0.4, 1, 0), v2=ifelse(x[,'p2'] 0.6, 0, 1)) I found the following error message *Error: unexpected symbol in p1-rnorm(200. mean Any 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. [[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] Random number
Ashta wrote: Hi All, I have the matrix called 'X' with 200 rows and 12 variables. I want to create 2 new variables (V1 and V2) based on random number generator p1-rnorm(200. mean=0, std=1) p2-rnorm(200. mean=0, std=1) x - cbind(x, v1=ifelse(x[,'p1'] 0.4, 1, 0), v2=ifelse(x[,'p2'] 0.6, 0, 1)) I found the following error message *Error: unexpected symbol in p1-rnorm(200. mean Any help? You need to increase the size of the font you're working with. It seems that your eyes can't distinguish a '.' from a ','! -Peter Ehlers * [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Solving a nonlinear System of equations
Hello there, I wish to solve the following nonlinear System of equations: + u1 - Vmax11*S1/(S1 + Km11 *(1 + S2/Km21)) - Vmax12*S1/( S1 + Km12 *(1+S2/Km22)) == 0 + u2 - Vmax22*S2/(S2 + Km22 *(1 + S1/Km12)) - Vmax21*S2/( S2 + Km21 *(1+S1/Km11)) == 0 + Vmax11*S1/(S1 + Km11 *(1 + S2/Km21)) + Vmax12*S1/( S1 + Km12 *(1+S2/Km22)) - d1*P1 == 0 + Vmax22*S2/(S2 + Km22 *(1 + S1/Km12)) + Vmax21*S2/( S2 + Km21 *(1+S1/Km11)) - d2*P2 == 0 S1, S2, P1, P2 are the Variables, u1, u2, Vmax11, Vmax12, Vmax21, Vmax22, Km11, Km12, Km21, Km22, d1 and d2 are Parameters which are given before the solving is attempted. My intention/endgame is to vary 2 or more of the Parameters and obtain a heatmap out of the resulting stationary points. Best Wishes, Andrej Schmelzer -- http://portal.gmx.net/de/go/dsl02 __ 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] COVARIANCE MATRIX FOR RANDOM EFFECTS - nlme
R-Help, I been using nlme to fit a model with 2 random effects. The correlation matrix I get with the VarCorr command does not seem to have the correct value for the correlation entry. E.g., below is a VarCorr matrix of random effects from data that I am working on: Variance StdDev Corr b1 14.386191885 3.79291338 b1 b30.002872538 0.05359606 0.109 Residual 0.052819504 0.22982494 The Corr value 0.109 does not appear to be correct. SAS gives a Corr value that is the square of the value got in R. I get nonsensical results when I use the value given by R. Could someone check this out. Charles O. Sabatia [[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] Solving a nonlinear System of equations
There are two packages for solving nonlinear systems: one is the `BBsolve' function in the BB package, and the other is `nleqslv' in the nleqslv package. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Andrej Iljitsch Schmelzer andrej-i-schmel...@gmx.de Date: Sunday, October 11, 2009 6:18 pm Subject: [R] Solving a nonlinear System of equations To: r-help@r-project.org Hello there, I wish to solve the following nonlinear System of equations: + u1 - Vmax11*S1/(S1 + Km11 *(1 + S2/Km21)) - Vmax12*S1/( S1 + Km12 *(1+S2/Km22)) == 0 + u2 - Vmax22*S2/(S2 + Km22 *(1 + S1/Km12)) - Vmax21*S2/( S2 + Km21 *(1+S1/Km11)) == 0 + Vmax11*S1/(S1 + Km11 *(1 + S2/Km21)) + Vmax12*S1/( S1 + Km12 *(1+S2/Km22)) - d1*P1 == 0 + Vmax22*S2/(S2 + Km22 *(1 + S1/Km12)) + Vmax21*S2/( S2 + Km21 *(1+S1/Km11)) - d2*P2 == 0 S1, S2, P1, P2 are the Variables, u1, u2, Vmax11, Vmax12, Vmax21, Vmax22, Km11, Km12, Km21, Km22, d1 and d2 are Parameters which are given before the solving is attempted. My intention/endgame is to vary 2 or more of the Parameters and obtain a heatmap out of the resulting stationary points. Best Wishes, Andrej Schmelzer -- __ R-help@r-project.org mailing list PLEASE do read the posting guide 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] Function Help
Hi there, I have created the function below: pirate-function(x){ a-x-1; b-a/5; c-a-b; d-c-1; e-d/5; f-d-e; g-f-1; h-g/5; i-g-h; j-i-1; k-j/5; l-j-k; m-l-1; n-m/5; o-m-n; final-o/5; final } I want to run this function until the output ('final') is an exact integer (e.g. 893.0 rather than 893.78332). I then need to find out what value of X (input) resulted in this integer. Could someone please help? I am relatively inexperienced at creating functions. Kind regards, James -- View this message in context: http://www.nabble.com/Function-Help-tp25848627p25848627.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] CRAN (and crantastic) updates this week
CRAN (and crantastic) updates this week New packages * AGSDest (1.0) Niklas Hack http://crantastic.org/packages/AGSDest Estimation in adaptive group sequential trials * atmi (1.0) Waldemar Kemler, Peter Schaffner, http://crantastic.org/packages/atmi Analysis and usage of the trading rules, which are based on technical market indicators as well as on the time series analysis. * gamesNws (0.5) Markus Schmidberger http://crantastic.org/packages/gamesNws This is a package with different card games (e.g. uno, poker, ...) and using a NWS Server as card table. You can play the games with your friends in the whole world. Just install a NWS Server at one machine, send the login data to your friends and start the game. * geneListPie (1.0) Xutao Deng http://crantastic.org/packages/geneListPie geneListPie package is for mapping a gene list to function categories defined in GOSlim or Kegg. The results can be plotted as a pie chart to provide a quick view of the genes distribution of the gene list among the function categories. The gene list must contain a list of gene symbols. The package contains a set of pre-processed gene sets obtained from Gene Ontology and MSigDB including human, mouse, rat and yeast. To provide a high level concise view, only GO slim and kegg are provided. The gene sets are regulared updated. User can also use customized gene sets. User can use the R Pie() or Pie3D() function for plotting the pie chart. Users can also choose to output the gene function mapping results and use external software such as Excel(R) for ploting. * sBF (1.0) Unknown http://crantastic.org/packages/sBF Smooth Backfitting for additive models using Nadaraya-Watson estimator * speedglm (0.1) Marco ENEA http://crantastic.org/packages/speedglm Fitting LMs and GLMs to large data sets by updating algorithms. * VIF (0.5) Dongyu Lin http://crantastic.org/packages/VIF This package implements a fast regression algorithm for building linear model for large data as defined in the paper VIF-Regression: A Fast Regression Algorithm for Large Data (2009) by Dongyu Lin, Dean P. Foster and Lyle H. Ungar. * WMCapacity (0.9) Richard D. Morey http://crantastic.org/packages/WMCapacity A GUI R implementation of hierarchical Bayesian models of working memory, used for analyzing change detection data. Updated packages ape (2.4), BAYSTAR (0.2-3), bdoc (1.1), bindata (0.9-16), bio.infer (1.2-5), boot (1.2-40), CADFtest (0.3-0), caret (4.25), cluster (1.12.1), cond (1.2-0), copula (0.8-12), corcounts (1.3), csampling (1.2-0), DEoptim (2.0-1), diseasemapping (0.5.3), doMC (1.2.0), dplR (1.1.9.3), earth (2.3-5), effects (2.0-8), ez (1.4.2), fds (1.1), FieldSim (2.1), FinTS (0.4-3), foreach (1.3.0), foreign (0.8-38), FrF2 (1.0), ftsa (1.1), gstat (0.9-63), IDPmisc (1.1.05), intamapInteractive (1.0-7), isa2 (0.2), iterators (1.0.3), ks (1.6.7), lattice (0.17-26), LogConcDEAD (1.4-0), marg (1.2-0), Matrix (0.999375-31), mcmc (0.7-3), MCPMod (1.0-5), metafor (0.5-5), MLCM (0.0-6), nlme (3.1-95), nlreg (1.2-0), operators (0.1-5), pegas (0.2), penalized (0.9-27), PKtools (1.5-0), psych (1.0-81), PTAk (1.2-0), rainbow (1.5), Rcmdr (1.5-3), RcmdrPlugin.DoE (0.5-4), RcmdrPlugin.DoE (0.5-5), rgcvpack (0.1-3), rgdal (0.6-19), RLadyBug (0.6-0), rmetasim (1.1.09), rms (2.1-0), RSiteSearch (1.0-6), seacarb (2.2), spdep (0.4-46), tmvtnorm (0.8-3), YourCast (1.1-5) New reviews --- * faraway, by aaronchall http://crantastic.org/reviews/37 * perm, by izahn http://crantastic.org/reviews/36 * ggplot2, by this.is.mvw http://crantastic.org/reviews/35 This email provided as a service for the R community by http://crantastic.org. Like it? Hate it? Please let us know: crana...@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] Loading same libraries (old version newest version) in r
Hi all, I require 2 RMySQL libraries in order to query from a database. 'RMySQL_0.7-4' (newest version) results in an error when more than 1 field is queried. ''RMySQL_0.5-11' (old version) resolves this issue where more than 1 field can be queried without any errors. However, other queries results in an error messeges (but no error messeges with 'RMySQL_0.7-4' package) Thus, I require two scripts each with different 'RMySQL' packages loaded to query from a database. Are there any commands that will do the job (i.e. loading 2 different libraries from different folder) without having to click 'Pakages' tool bar in th RGui console? Your help in resolving this issue would be appreciated. Steven [[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] Ubuntu, Revolutions, R
A.J. Rossini wrote: Ubuntu is a commercial distribution, for loose definitions of commercial. Why shouldn't they cut a deal with Revolution, who is doing a very similar thing? If you want something closer to the ideal of volunteer-driven free as in beer and speech, you'll need to stick with Debian. Canonical and Revolution have very similar business models. And they just happen to have similar relationships to volunteer-driven development in Debian and R-Core. -tony I sincerely hope I did not come across as overly negative in my original query. I am glad that companies such as Canonical (Ubuntu) and REvolutions Computing (R-Project) are able to build business plans via free software. Although Canonical has a less than perfect track-record when it comes to releasing all of it's code (example - UbuntuOne _server_ code), it appears REvolution Computing has released the code to it's extensions. I do however wish there had been more communication to end-users about this change. Had the REvolution extensions merely been added to the Ubuntu repositories, such communication would have been less important. But, R now starts with a message about installing the REvolution Computing extensions if it can't find them. My OP was an attempt to learn more about the nature of the changes (did they affect r-core) and the maturity/dependability of these extensions. Truthfully, I'm looking forward to the next project where I can some of this out. The foreach() function seems really really nifty. (I can't believe I just said something positive about using a loop in R.) All that being said, I would agree that a purist would probably find Debian to be a better match. But, I am not much of a purist. -- View this message in context: http://www.nabble.com/Ubuntu%2C-Revolutions%2C-R-tp25744817p25849088.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] Function Help
jimdare wrote: Hi there, I have created the function below: pirate-function(x){ a-x-1; b-a/5; c-a-b; d-c-1; e-d/5; f-d-e; g-f-1; h-g/5; i-g-h; j-i-1; k-j/5; l-j-k; m-l-1; n-m/5; o-m-n; final-o/5; final } I want to run this function until the output ('final') is an exact integer (e.g. 893.0 rather than 893.78332). I then need to find out what value of X (input) resulted in this integer. Could someone please help? I am relatively inexperienced at creating functions. Kind regards, James You could approach this problem by setting it up as an optimization problem where the task is to guess the value of x such that the squared difference between pirate(x) and your target value is minimized. The difference is squared in order to ensure the optimizer attempts to drive the difference to 0 instead of -infinity. A function that calculates the squared difference between any function evaluated at a point x and some target value is: sqDiff - function( x, funObj, target ){ return( ( target - funObj(x) )^2 ) } You can then use R's nlm() function in an attempt to discover the value of x that results in your target value of 893. This requires specifying an initial guess p: nlm( sqDiff, p = 5000, funObj = pirate, target = 893 ) $minimum [1] 1.996023e-07 $estimate [1] 13634.3 $gradient [1] -3.72529e-14 $code [1] 1 $iterations [1] 3 The solver came up with an estimate of 13634.3 for x: pirate( 13634.3 ) [1] 892.9996 Achieving a solution that provides the exact value of 893 is very unlikely using numerical optimization since these techniques involve refining a series of guesses until one of the guesses is good enough-- i.e. within 1*10^{-6} of your target value-- at which point the algorithm terminates. To get an answer that provides the target number of 893 exactly you will probably have to use a symbolic solver-- the Ryacas or rSymPy packages provide interfaces to computer algebra systems that may have the necessary symbolic tools to help you here. Good luck! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/Function-Help-tp25848627p25849148.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] Loading data to Trellis barchart plot.
Dear all, I have a question about loading the data to barchart plot. I know this could be a very easy question, but I just can not get my head around. What I need to do is to create a trellis plots barchart style (horizontal bar), with levels of one variable (ie. variable colour in my example) as ylab and frequency as xlab on each trellis plot. The trellis plots is separated based on levels of another variable ie variable id in my example. . For example, library(lattice) dataset.frame - data.frame(id=c(a,b,c,a,c,b,a),colour=c(blue,green,red,red,red,green,green))) barchart(dataset.frame$colour|dataset.frame$id,stack=FALSE) *it comes error message like this:* Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : invalid 'times' value In addition: Warning message: In Ops.factor(dataset.frame$colour, dataset.frame$id) : | not meaningful for factors *Then, I try to create a table rather than data frame. E.g.* dataset.table - table(data.frame(id=c(a,b,c,a,c,b,a),colour=c(blue,green,red,red,red,green,green))) barchart(dataset.table$colour|dataset.table$id,stack=FALSE) *it also comes with error message:* Error in dataset.table$colour | dataset.table$id : operations are possible only for numeric or logical types In addition: Warning messages: 1: In dataset.table$colour : $ operator is invalid for atomic vectors, returning NULL 2: In dataset.table$id : $ operator is invalid for atomic vectors, returning NULL *I have no problem creating a single barchart but not trellis barchart. please guide me on this.* * * *Thanks a lot.* ** *Rene * ** [[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] add=TRUE function not working
Hey everybody, I have a matrix with three columns. I want to plot two columns (independent variable) against one column (the defendant). This is my code and the error associated with it: plot(p, q, data=columns) plot(pprime,q, add=TRUE) Warning messages: 1: In plot.window(...) : add is not a graphical parameter 2: In plot.xy(xy, type, ...) : add is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 5: In box(...) : add is not a graphical parameter 6: In title(...) : add is not a graphical parameter How do I resolve this problem? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add=TRUE function not working
You're going about it the wrong way: plot(p, q1) lines(p, q2) or points(p, q2) depending on what you want it to look like. Sarah On Sun, Oct 11, 2009 at 8:52 PM, Mehdi Khan mwk...@ucdavis.edu wrote: Hey everybody, I have a matrix with three columns. I want to plot two columns (independent variable) against one column (the defendant). This is my code and the error associated with it: plot(p, q, data=columns) plot(pprime,q, add=TRUE) Warning messages: 1: In plot.window(...) : add is not a graphical parameter 2: In plot.xy(xy, type, ...) : add is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 5: In box(...) : add is not a graphical parameter 6: In title(...) : add is not a graphical parameter How do I resolve this problem? thanks! -- Sarah Goslee http://www.functionaldiversity.org __ 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] Function Help
cls59 wrote: jimdare wrote: Hi there, I have created the function below: pirate-function(x){ a-x-1; b-a/5; c-a-b; d-c-1; e-d/5; f-d-e; g-f-1; h-g/5; i-g-h; j-i-1; k-j/5; l-j-k; m-l-1; n-m/5; o-m-n; final-o/5; final } I want to run this function until the output ('final') is an exact integer (e.g. 893.0 rather than 893.78332). I then need to find out what value of X (input) resulted in this integer. Could someone please help? I am relatively inexperienced at creating functions. Kind regards, James You could approach this problem by setting it up as an optimization problem where the task is to guess the value of x such that the squared difference between pirate(x) and your target value is minimized. The difference is squared in order to ensure the optimizer attempts to drive the difference to 0 instead of -infinity. A function that calculates the squared difference between any function evaluated at a point x and some target value is: sqDiff - function( x, funObj, target ){ return( ( target - funObj(x) )^2 ) } You can then use R's nlm() function in an attempt to discover the value of x that results in your target value of 893. This requires specifying an initial guess p: nlm( sqDiff, p = 5000, funObj = pirate, target = 893 ) $minimum [1] 1.996023e-07 $estimate [1] 13634.3 $gradient [1] -3.72529e-14 $code [1] 1 $iterations [1] 3 The solver came up with an estimate of 13634.3 for x: pirate( 13634.3 ) [1] 892.9996 Achieving a solution that provides the exact value of 893 is very unlikely using numerical optimization since these techniques involve refining a series of guesses until one of the guesses is good enough-- i.e. within 1*10^{-6} of your target value-- at which point the algorithm terminates. To get an answer that provides the target number of 893 exactly you will probably have to use a symbolic solver-- the Ryacas or rSymPy packages provide interfaces to computer algebra systems that may have the necessary symbolic tools to help you here. Good luck! -Charlie If you put all of this into Yacas (or Mathematica) you get: In Simplify(final) Out (4*(256*x-2101))/15625 You can then pick your solution: In Solve(z==1,x) Out {x==24029/1024} Then: pirate(24029/1024) is exactly 1 In Solve(z==893,x) Out {x==13961529/1024} pirate(13961529/1024) is exactly 893 and so forth. -- View this message in context: http://www.nabble.com/Function-Help-tp25848627p25849340.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] add=TRUE function not working
x1=rnorm(100) x2=rnorm(100) e=rnorm(100) y=1.5*x1+x2+e plot(y~x1,pch=1,xlim=c(min(x1,x2),max(x1,x2))) points(y~x2,pch=16) HTH Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Mehdi Khan Gesendet: Sunday, October 11, 2009 8:52 PM An: r-help@r-project.org Betreff: [R] add=TRUE function not working Hey everybody, I have a matrix with three columns. I want to plot two columns (independent variable) against one column (the defendant). This is my code and the error associated with it: plot(p, q, data=columns) plot(pprime,q, add=TRUE) Warning messages: 1: In plot.window(...) : add is not a graphical parameter 2: In plot.xy(xy, type, ...) : add is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 5: In box(...) : add is not a graphical parameter 6: In title(...) : add is not a graphical parameter How do I resolve this problem? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add=TRUE function not working
Okay it worked, is there any way I can define the scale though? thanks a lot! On Sun, Oct 11, 2009 at 6:08 PM, Daniel Malter dan...@umd.edu wrote: x1=rnorm(100) x2=rnorm(100) e=rnorm(100) y=1.5*x1+x2+e plot(y~x1,pch=1,xlim=c(min(x1,x2),max(x1,x2))) points(y~x2,pch=16) HTH Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Mehdi Khan Gesendet: Sunday, October 11, 2009 8:52 PM An: r-help@r-project.org Betreff: [R] add=TRUE function not working Hey everybody, I have a matrix with three columns. I want to plot two columns (independent variable) against one column (the defendant). This is my code and the error associated with it: plot(p, q, data=columns) plot(pprime,q, add=TRUE) Warning messages: 1: In plot.window(...) : add is not a graphical parameter 2: In plot.xy(xy, type, ...) : add is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 5: In box(...) : add is not a graphical parameter 6: In title(...) : add is not a graphical parameter How do I resolve this problem? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] add=TRUE function not working
What do you mean by define the scale? -- On Oct 11, 2009, at 9:26 PM, Mehdi Khan wrote: Okay it worked, is there any way I can define the scale though? thanks a lot! On Sun, Oct 11, 2009 at 6:08 PM, Daniel Malter dan...@umd.edu wrote: x1=rnorm(100) x2=rnorm(100) e=rnorm(100) y=1.5*x1+x2+e plot(y~x1,pch=1,xlim=c(min(x1,x2),max(x1,x2))) points(y~x2,pch=16) HTH Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] Im Auftrag von Mehdi Khan Gesendet: Sunday, October 11, 2009 8:52 PM An: r-help@r-project.org Betreff: [R] add=TRUE function not working Hey everybody, I have a matrix with three columns. I want to plot two columns (independent variable) against one column (the defendant). This is my code and the error associated with it: plot(p, q, data=columns) plot(pprime,q, add=TRUE) Warning messages: 1: In plot.window(...) : add is not a graphical parameter 2: In plot.xy(xy, type, ...) : add is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : add is not a graphical parameter 5: In box(...) : add is not a graphical parameter 6: In title(...) : add is not a graphical parameter How do I resolve this problem? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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 Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] r package for Probabilistic neural networks?
I am wondering if there is an implementation of PNN by Specht in R. thank you so much! -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller __ 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] Loading data to Trellis barchart plot.
Hi I think the following will help: #Load some packages library(lattice) library(reshape) #Sample data dataset.frame - data.frame(id=c(a,b,c,a,c,b,a),colour=c(blue,green,red,red,red,green,green)) # calculate the counts dataset.table - table(dataset.frame) #and reshape the table dataset.melt - melt(dataset.table,measure.vars=levels(dataset.frame$colour), id.vars=id) #now plot barchart(colour~value|id,dataset.melt) #for extra effect add some colours barchart(colour~value|id,dataset.melt,col=levels(dataset.melt$colour)) Schalk On Mon, Oct 12, 2009 at 2:52 AM, kaixin maleA kaixinma...@gmail.com wrote: Dear all, I have a question about loading the data to barchart plot. I know this could be a very easy question, but I just can not get my head around. What I need to do is to create a trellis plots barchart style (horizontal bar), with levels of one variable (ie. variable colour in my example) as ylab and frequency as xlab on each trellis plot. The trellis plots is separated based on levels of another variable ie variable id in my example. . For example, library(lattice) dataset.frame - data.frame(id=c(a,b,c,a,c,b,a),colour=c(blue,green,red,red,red,green,green))) barchart(dataset.frame$colour|dataset.frame$id,stack=FALSE) *it comes error message like this:* Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : invalid 'times' value In addition: Warning message: In Ops.factor(dataset.frame$colour, dataset.frame$id) : | not meaningful for factors *Then, I try to create a table rather than data frame. E.g.* dataset.table - table(data.frame(id=c(a,b,c,a,c,b,a),colour=c(blue,green,red,red,red,green,green))) barchart(dataset.table$colour|dataset.table$id,stack=FALSE) *it also comes with error message:* Error in dataset.table$colour | dataset.table$id : operations are possible only for numeric or logical types In addition: Warning messages: 1: In dataset.table$colour : $ operator is invalid for atomic vectors, returning NULL 2: In dataset.table$id : $ operator is invalid for atomic vectors, returning NULL *I have no problem creating a single barchart but not trellis barchart. please guide me on this.* * * *Thanks a lot.* ** *Rene * ** [[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.