Re: [R] Simple question about function with glm
Thank you akk. I know it is not statistically sounded to check the distribution of response before glm. I will check the distribution of xmodel$residuals later on. About the program problem. It can print summary(xmodel) but not confint(xmodel) by amending my code as suggested by Bill Venables. Regards, CH On 5/7/07, Ben Bolker [EMAIL PROTECTED] wrote: Bill.Venables at csiro.au writes: Finally, I'm a bit puzzled why you use glm() when the simpler lm() would have done the job. You are fitting a linear model and do not need the extra paraphernaila that generalized linear models require. Bill Venables. Perhaps the original poster is confused about the difference between general (a la PROC GLM) and generalized (glm) linear models? The code is also a little puzzling because the same tests seem to be run whether p0.05 or not. Perhaps the code will eventually be written to log-transform the data if it fails the normality test? [ hint: ?boxcox in the MASS package might be a better way to go ] Ben Bolker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- The scientists of today think deeply instead of clearly. One must be sane to think clearly, but one can think deeply and be quite insane. Nikola Tesla http://www.macgrass.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simple question about function with glm
Dear all, I coded a function called u.glm u.glm - function (x,ahi,age,bmiz,gender) { library(nortest) lil.rslt - lillie.test(x) if (lil.rslt$p.value 0.05) { cat(Logtrans=0, lillie=,lil.rslt$p.value,\n) xmodel-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) } else { cat(Logtrans=1, lillie=,lil.rslt$p.value,\n) xmodel-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) } } Basically I just want to test the response variable for normality before modeling. When I try to use this function, it can do the lillie's test but failed to do the glm. What's wrong with my code? Regards, CH -- The scientists of today think deeply instead of clearly. One must be sane to think clearly, but one can think deeply and be quite insane. Nikola Tesla http://www.macgrass.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about function with glm
There is a statistical problem and a code problem. The statistical problem is that if your 'x' has a mean that depends non-trivially on predictors, then you would not expect its distribution ignoring predictors to be normal. You would expect the residuals after modelling to be normal. Basically you cannot sensibly test normality of the response before you fit the model. It's a very common mistake, even if rather an obvious one. The code problem is that, do you really know whether your models have been fitted or not? The 'summary(xmodel)' part of your function below will not print anything out, so if you were expecting something from that you would be disappointed. You might try replacing summary(xmodel) confint(xmodel) By print(summary(xmodel)) print(confint(xmodel)) But this is not really a very good paradigm in genera. Finally, I'm a bit puzzled why you use glm() when the simpler lm() would have done the job. You are fitting a linear model and do not need the extra paraphernaila that generalized linear models require. Bill Venables. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chung-hong Chan Sent: Sunday, 6 May 2007 6:47 PM To: r-help@stat.math.ethz.ch Subject: [R] Simple question about function with glm Dear all, I coded a function called u.glm u.glm - function (x,ahi,age,bmiz,gender) { library(nortest) lil.rslt - lillie.test(x) if (lil.rslt$p.value 0.05) { cat(Logtrans=0, lillie=,lil.rslt$p.value,\n) xmodel-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) } else { cat(Logtrans=1, lillie=,lil.rslt$p.value,\n) xmodel-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) } } Basically I just want to test the response variable for normality before modeling. When I try to use this function, it can do the lillie's test but failed to do the glm. What's wrong with my code? Regards, CH -- The scientists of today think deeply instead of clearly. One must be sane to think clearly, but one can think deeply and be quite insane. Nikola Tesla http://www.macgrass.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about function with glm
Bill.Venables at csiro.au writes: Finally, I'm a bit puzzled why you use glm() when the simpler lm() would have done the job. You are fitting a linear model and do not need the extra paraphernaila that generalized linear models require. Bill Venables. Perhaps the original poster is confused about the difference between general (a la PROC GLM) and generalized (glm) linear models? The code is also a little puzzling because the same tests seem to be run whether p0.05 or not. Perhaps the code will eventually be written to log-transform the data if it fails the normality test? [ hint: ?boxcox in the MASS package might be a better way to go ] Ben Bolker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] simple question on one-sided p-values for coef() on output of lm()
Dear list, I was wondering if it is possible to get the p-values for one-sided tests on the parameters of a linear regression. For instance, I use lm() and store the result in an object. lm() gives me a matrix, using summary() and coef() on which gives me a matrix containing the coefficients, the standard errors, the t-statistics and the two-sided p-values by default. Can I get it to provide me with one-sided p-values (something like alternative less than or greater than)? Many thanks and best wishes, Ranjan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simple question on one-sided p-values for coef() on output of lm()
On Wed, 21 Feb 2007, Ranjan Maitra wrote: I was wondering if it is possible to get the p-values for one-sided tests on the parameters of a linear regression. For instance, I use lm() and store the result in an object. lm() gives me a matrix, using summary() and coef() on which gives me a matrix containing the coefficients, the standard errors, the t-statistics and the two-sided p-values by default. Can I get it to provide me with one-sided p-values (something like alternative less than or greater than)? Not 'it', but you can easily do the calculation yourself from the output. E.g. example(lm) s - summary(lm.D90) pt(coef(s)[, 2], s$df[2], lower=FALSE) # or TRUE -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simple question on one-sided p-values for coef() on output of lm()
Yes, of course! Thank you. So, I guess the answer is that R itself can not be made to do so directly. Many thanks for confirming this. Sincerely, Ranjan On Wed, 21 Feb 2007 20:23:55 + (GMT) Prof Brian Ripley [EMAIL PROTECTED] wrote: On Wed, 21 Feb 2007, Ranjan Maitra wrote: I was wondering if it is possible to get the p-values for one-sided tests on the parameters of a linear regression. For instance, I use lm() and store the result in an object. lm() gives me a matrix, using summary() and coef() on which gives me a matrix containing the coefficients, the standard errors, the t-statistics and the two-sided p-values by default. Can I get it to provide me with one-sided p-values (something like alternative less than or greater than)? Not 'it', but you can easily do the calculation yourself from the output. E.g. example(lm) s - summary(lm.D90) pt(coef(s)[, 2], s$df[2], lower=FALSE) # or TRUE -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simple question on one-sided p-values for coef() on output of lm()
Quoting Ranjan Maitra [EMAIL PROTECTED]: Yes, of course! Thank you. So, I guess the answer is that R itself can not be made to do so directly. Many thanks for confirming this. Sincerely, Ranjan On Wed, 21 Feb 2007 20:23:55 + (GMT) Prof Brian Ripley [EMAIL PROTECTED] wrote: On Wed, 21 Feb 2007, Ranjan Maitra wrote: I was wondering if it is possible to get the p-values for one-sided tests on the parameters of a linear regression. For instance, I use lm() and store the result in an object. lm() gives me a matrix, using summary() and coef() on which gives me a matrix containing the coefficients, the standard errors, the t-statistics and the two-sided p-values by default. Can I get it to provide me with one-sided p-values (something like alternative less than or greater than)? Not 'it', but you can easily do the calculation yourself from the output. E.g. example(lm) s - summary(lm.D90) pt(coef(s)[, 2], s$df[2], lower=FALSE) # or TRUE I think it should be pt(coef(s)[, 3], s$df[2], lower=FALSE) # or TRUE ^ Best, Dimitris -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] simple question on intervals
Hi, I have a number (correlation coefficient) x in [-1,1], and a color palette col-grey(1:N/N) for a given N. I want to assign a color from col to x which corresponds to x in levels of cut(-1:1,N). So for N-4 and x-0.3, the color should be col[3]. For N-4 and x--0.8, the color should be col[1], etc. Thank you for your help, Serguei [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simple question on intervals
I have a number (correlation coefficient) x in [-1,1], and a color palette col-grey(1:N/N) for a given N. I want to assign a color from col to x which corresponds to x in levels of cut(-1:1,N). So for N-4 and x-0.3, the color should be col[3]. For N-4 and x--0.8, the color should be col[1], etc. findInterval(-0.3,seq(-1,1,2/4)) HTH ido __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simple question about Lists
Hello, I know this must be a very simple problem, but I can't work it out from the documentation that is available. I've got a list of data I would like to plot (the weights of a single neuron that was trained using the neural package). The problem I'm encountering is that this set of weights, are in the form of a list. network$weigth[1] [[1]] [,1] [1,] -0.04687623 [2,] -0.54087443 [3,] -1.68130221 [4,] -0.82295266 [5,] 1.60848361 [6,] 1.55903277 [7,] 0.29005900 [8,] 1.24387657 [9,] -0.05129092 [10,] -1.22469042 [11,] -2.64470326 [12,] 0.10517494 [13,] 1.87561741 [14,] 1.93962447 [15,] 0.99212323 [16,] 0.46430803 [17,] -0.31660246 [18,] -0.81997588 [19,] 0.22277782 [20,] 0.97456769 [21,] 0.46083111 [22,] 1.46876956 [23,] -0.19702465 [24,] -0.34898054 [25,] 1.22504724 Now, I've tried as.vector to convert it to a vector for plotting. Doesn't work. Tried as.matrix, that too doesn't work. I've tried accessing individual elements, but that doesn't work as network$weigth [1] returns what seems to me is a matrix but it doens't act like a matrix. Any help would be much obliged. Wee-Jin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about Lists
Hello, You can try to merge network$wieght in the data frame, and the plot a first row from it. DataF - do.call (rbind,network$weight) Andris On Ceturtdiena, 2. Novembris 2006 12:53, Wee-Jin Goh wrote: Hello, I know this must be a very simple problem, but I can't work it out from the documentation that is available. I've got a list of data I would like to plot (the weights of a single neuron that was trained using the neural package). The problem I'm encountering is that this set of weights, are in the form of a list. network$weigth[1] [[1]] [,1] [1,] -0.04687623 [2,] -0.54087443 [3,] -1.68130221 [4,] -0.82295266 [5,] 1.60848361 [6,] 1.55903277 [7,] 0.29005900 [8,] 1.24387657 [9,] -0.05129092 [10,] -1.22469042 [11,] -2.64470326 [12,] 0.10517494 [13,] 1.87561741 [14,] 1.93962447 [15,] 0.99212323 [16,] 0.46430803 [17,] -0.31660246 [18,] -0.81997588 [19,] 0.22277782 [20,] 0.97456769 [21,] 0.46083111 [22,] 1.46876956 [23,] -0.19702465 [24,] -0.34898054 [25,] 1.22504724 Now, I've tried as.vector to convert it to a vector for plotting. Doesn't work. Tried as.matrix, that too doesn't work. I've tried accessing individual elements, but that doesn't work as network$weigth [1] returns what seems to me is a matrix but it doens't act like a matrix. Any help would be much obliged. Wee-Jin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about Lists
Try this: L - list(matrix(1:10, 10)) L [[1]] [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 plot(L[[1]]) If your object is somehow different then please display it like this: dput(x, control = all) where x is your object so we can reproduce it exactly. On 11/2/06, Wee-Jin Goh [EMAIL PROTECTED] wrote: Hello, I know this must be a very simple problem, but I can't work it out from the documentation that is available. I've got a list of data I would like to plot (the weights of a single neuron that was trained using the neural package). The problem I'm encountering is that this set of weights, are in the form of a list. network$weigth[1] [[1]] [,1] [1,] -0.04687623 [2,] -0.54087443 [3,] -1.68130221 [4,] -0.82295266 [5,] 1.60848361 [6,] 1.55903277 [7,] 0.29005900 [8,] 1.24387657 [9,] -0.05129092 [10,] -1.22469042 [11,] -2.64470326 [12,] 0.10517494 [13,] 1.87561741 [14,] 1.93962447 [15,] 0.99212323 [16,] 0.46430803 [17,] -0.31660246 [18,] -0.81997588 [19,] 0.22277782 [20,] 0.97456769 [21,] 0.46083111 [22,] 1.46876956 [23,] -0.19702465 [24,] -0.34898054 [25,] 1.22504724 Now, I've tried as.vector to convert it to a vector for plotting. Doesn't work. Tried as.matrix, that too doesn't work. I've tried accessing individual elements, but that doesn't work as network$weigth [1] returns what seems to me is a matrix but it doens't act like a matrix. Any help would be much obliged. Wee-Jin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simple question on a function
I would like to apply the following function to the rows of the matrix mat, so that freq[1],...,freq[4] are the four elements of each row. min_chi2-function(freq){ obj-function(x){ (freq[1]-(1-x[1])*(1-x[2])-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[1]+ (freq[2]-(1-x[1])*x[2]+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[2]+ (freq[3]-x[1]*(1-x[2])+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[3]+ (freq[4]-x[1]*x[2]-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[4] } optim(c(0.1,0.1,0.1),obj,NULL,method=BFGS)$par } mat-matrix(c(0.4,0.1,0.1,0.4), byrow=TRUE, nrow=10, ncol=4) Questions: 1. How to do this using the apply function? 2. Can opmit be used directly, i.e. without needing to define the function min_chi2? 3. How to pass the vector of initial conditions (c(0.1,0.1,0.1)) as an argument to apply? The output should be a 10x3 matrix containing 0.5 0.5 0.6 in each row. Thanks a lot, Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail: [EMAIL PROTECTED] http://www.wifo.ac.at/Serguei.Kaniovski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question on a function
Dear Serguei There might be more efficient ways, but this should work: ## Define function that you want to optimize. In your case I ## copied your code, but included freq as a second argument: fun - function(x, freq) { (freq[1]-(1-x[1])*(1-x[2])-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[1]+ (freq[2]-(1-x[1])*x[2]+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[2]+ (freq[3]-x[1]*(1-x[2])+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[3]+ (freq[4]-x[1]*x[2]-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[4] } ## Define mat with values for freq (your code) mat-matrix(c(0.4,0.1,0.1,0.4), byrow=TRUE, nrow=10, ncol=4) ## Use apply on mat apply(mat, 1, function(freq, start) optim(start, fun, method=BFGS, freq = freq)$par, start = c(0.1,0.1,0.1)) You still can use t() to transpose the matrix if you want the solutions by row instead of columns. Please remark that in general optim returns a list, including several arguments, e.g. convergence that indicates if optim has converge. Since you wanted a matrix I only returned optim(...)$par. This might be dangerous since the additional information gets lost. Maybe it is better to save the output in a list. You can try: apply(mat, 1, function(freq, start) optim(start, fun, method=BFGS, freq = freq), start = c(0.1,0.1,0.1)) to see the difference. Hope this helps Christoph -- Credit and Surety PML study: visit our web page www.cs-pml.org -- Christoph Buser [EMAIL PROTECTED] Seminar fuer Statistik, LEO C13 ETH Zurich 8092 Zurich SWITZERLAND phone: x-41-44-632-4673 fax: 632-1228 http://stat.ethz.ch/~buser/ -- Serguei Kaniovski writes: I would like to apply the following function to the rows of the matrix mat, so that freq[1],...,freq[4] are the four elements of each row. min_chi2-function(freq){ obj-function(x){ (freq[1]-(1-x[1])*(1-x[2])-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[1]+ (freq[2]-(1-x[1])*x[2]+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[2]+ (freq[3]-x[1]*(1-x[2])+x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[3]+ (freq[4]-x[1]*x[2]-x[3]*sqrt(x[1]*(1-x[1])*x[2]*(1-x[2])))^2/freq[4] } optim(c(0.1,0.1,0.1),obj,NULL,method=BFGS)$par } mat-matrix(c(0.4,0.1,0.1,0.4), byrow=TRUE, nrow=10, ncol=4) Questions: 1. How to do this using the apply function? 2. Can opmit be used directly, i.e. without needing to define the function min_chi2? 3. How to pass the vector of initial conditions (c(0.1,0.1,0.1)) as an argument to apply? The output should be a 10x3 matrix containing 0.5 0.5 0.6 in each row. Thanks a lot, Serguei -- ___ Austrian Institute of Economic Research (WIFO) Name: Serguei Kaniovski P.O.Box 91 Tel.: +43-1-7982601-231 Arsenal Objekt 20 Fax: +43-1-7989386 1103 Vienna, Austria Mail: [EMAIL PROTECTED] http://www.wifo.ac.at/Serguei.Kaniovski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] simple question about variables....
Dear R users, I have a simple question on variable manipulation. Imagine I have an object OBJ that has toto as one of its variables. I would like to understand why if I do varname - toto OBJ$varname returns no results whereas OBJ[varname]returns the column entitled toto Thanks for your help. Stéphane. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question about variables....
see ?$ 'x$name' is equivalent to 'x[[name]]' so you need use : eval(parse(text = paste(OBJ$, varname))) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Stéphane Cruveiller a écrit : Dear R users, I have a simple question on variable manipulation. Imagine I have an object OBJ that has toto as one of its variables. I would like to understand why if I do varname - toto OBJ$varname returns no results whereas OBJ[varname]returns the column entitled toto Thanks for your help. Stéphane. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question about variables....
Stéphane Cruveiller wrote: Dear R users, I have a simple question on variable manipulation. Imagine I have an object OBJ that has toto as one of its variables. I would like to understand why if I do varname - toto OBJ$varname returns no results whereas OBJ[varname]returns the column entitled toto Thanks for your help. Stéphane. because if the value of `varname' is substituted in the expressions, in the first case that yields OBJ$toto and in the second OBJ[toto] the latter is valid, the former is not (you'd need `OBJ$toto' there), read ` ?$ ': ...Both '[[' and '$' select a single element of the list. The main difference is that '$' does not allow computed indices, whereas '[[' does. 'x$name' is equivalent to 'x[[name]]'... not, too, the difference between `[' (sublist) and `[[' (single element extraction) joerg __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question about variables....
Thx for the tip Stéphane. Jacques VESLOT a écrit : see ?$ 'x$name' is equivalent to 'x[[name]]' so you need use : eval(parse(text = paste(OBJ$, varname))) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Stéphane Cruveiller a écrit : Dear R users, I have a simple question on variable manipulation. Imagine I have an object OBJ that has toto as one of its variables. I would like to understand why if I do varname - toto OBJ$varname returns no results whereas OBJ[varname]returns the column entitled toto Thanks for your help. Stéphane. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question about variables....
OBJ$toto works to... b - as.data.frame(matrix(1:4,2)) b V1 V2 1 1 3 2 2 4 b$V1 [1] 1 2 but varname is not evaluated in OBJ$varname. --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Joerg van den Hoff a écrit : Stéphane Cruveiller wrote: Dear R users, I have a simple question on variable manipulation. Imagine I have an object OBJ that has toto as one of its variables. I would like to understand why if I do varname - toto OBJ$varname returns no results whereas OBJ[varname]returns the column entitled toto Thanks for your help. Stéphane. because if the value of `varname' is substituted in the expressions, in the first case that yields OBJ$toto and in the second OBJ[toto] the latter is valid, the former is not (you'd need `OBJ$toto' there), read ` ?$ ': ...Both '[[' and '$' select a single element of the list. The main difference is that '$' does not allow computed indices, whereas '[[' does. 'x$name' is equivalent to 'x[[name]]'... not, too, the difference between `[' (sublist) and `[[' (single element extraction) joerg __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] simple question
Its just a simple question I guess: I have a vector with missing information like x-c(0,1,31,131,NA,133,NA,310,NA,112,3,1,2,93) How can I make a vector like this no missing in it. I used the x[x0] commabd and tried some more, with no success. thx Korbinian __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question
Hi, Korbinian von Blanckenburg wrote: Its just a simple question I guess: I have a vector with missing information like x-c(0,1,31,131,NA,133,NA,310,NA,112,3,1,2,93) How can I make a vector like this no missing in it. I used the x[x0] commabd and tried some more, with no success. Try na.omit() HTH, Kevin -- Ko-Kang Kevin Wang PhD Student Centre for Bioinformation Science Building 27, Room 1004 Mathematical Sciences Institute (MSI) Australian National University Canberra, ACT 2601 Australia Homepage: http://wwwmaths.anu.edu.au/~wangk/ Ph (W): +61-2-6125-2431 Ph (H): +61-2-6125-7488 Ph (M): +61-40-451-8301 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question
Em Sáb 22 Out 2005 10:07, Korbinian von Blanckenburg escreveu: Its just a simple question I guess: I have a vector with missing information like x-c(0,1,31,131,NA,133,NA,310,NA,112,3,1,2,93) How can I make a vector like this no missing in it. I used the x[x0] commabd and tried some more, with no success. thx Korbinian Hi, try this: x[is.na(x)==FALSE] Inte Ronaldo -- There is a fly on your nose. -- | // | \\ [***] | ( õ õ ) [Ronaldo Reis Júnior] | V [UFV/DBA-Entomologia] |/ \ [36570-000 Viçosa - MG ] | /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [EMAIL PROTECTED]] |/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] |( `- ) [***] | _/ \_Powered by GNU/Debian Woody/Sarge __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question
Ronaldo Reis-Jr. [EMAIL PROTECTED] writes: try this: x[is.na(x)==FALSE] whinge x[!is.na(x)] -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Simple question.....
Hi all user R, My simple question is...I have a vector of names of predictors, text-c(datem,cola,eslom)...I try to plot the model with this predictor in sequence loop, for(i in 1:3){ png(paste(fig_,i,sep=)) plot(preplot.gam(mod9)[[i]],se=T,rug=F,main=,xaxt=n,ylab=,xlab=) axis(1,as.numeric(text[i]),as.character(text[i]),cex.axis=.9) dev.off() } But the line with function axis get error Error in axis(side, at, labels, tick, line, pos, outer, font, vfont, lty, : no locations are finite I put in shell text[i] give datem, I try to erase the , can not search what is the function to erase this character (). Samebody can help me to erase , when put the predictor without , datem, there not problem Thank for all Fernando Espindola R. Division Investigacion Pesquera Instituto de Fomento Pesquero Blanco 839 Valparaiso - CHILE [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Simple question.....
See ?get. Andy From: Fernando Espíndola Hi all user R, My simple question is...I have a vector of names of predictors, text-c(datem,cola,eslom)...I try to plot the model with this predictor in sequence loop, for(i in 1:3){ png(paste(fig_,i,sep=)) plot(preplot.gam(mod9)[[i]],se=T,rug=F,main=,xaxt=n,ylab= ,xlab=) axis(1,as.numeric(text[i]),as.character(text[i]),cex.axis=.9) dev.off() } But the line with function axis get error Error in axis(side, at, labels, tick, line, pos, outer, font, vfont, lty, : no locations are finite I put in shell text[i] give datem, I try to erase the , can not search what is the function to erase this character (). Samebody can help me to erase , when put the predictor without , datem, there not problem Thank for all Fernando Espindola R. Division Investigacion Pesquera Instituto de Fomento Pesquero Blanco 839 Valparaiso - CHILE [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] simple question: reading lower triangular matrix
Dear list, I will like to learn how to read a lower triangular matrix in R. The input file *.txt have the following format: A B C D E A 0 B 10 C 250 D 3680 E 479 100 How this can be done? Thanks in advance for your help Rogério __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question: reading lower triangular matrix
On Tue, 2005-07-12 at 14:37 -0300, Rogério Rosa da Silva wrote: Dear list, I will like to learn how to read a lower triangular matrix in R. The input file *.txt have the following format: A B C D E A 0 B 10 C 250 D 3680 E 479 100 How this can be done? Thanks in advance for your help Rogério I don't know that this is the easiest way of doing it, but here is one approach: # I saved your data above in a file called test.txt # Read the first line of test.txt to get the colnames as chars col.names - unlist(read.table(test.txt, nrow = 1, as.is = TRUE)) # now read the rest of the file using 'fill = TRUE' to pad lines # with NAs # skip the first line # set the row.names as the first column in the text file # coerce to a matrix df - as.matrix(read.table(test.txt, fill = TRUE, skip = 1, row.names = 1)) # Now set the colnames of df colnames(df) - col.names df A B C D E A 0 NA NA NA NA B 1 0 NA NA NA C 2 5 0 NA NA D 3 6 8 0 NA E 4 7 9 10 0 If you should further want to set the diagonal to NA: diag(df) - NA df A B C D E A NA NA NA NA NA B 1 NA NA NA NA C 2 5 NA NA NA D 3 6 8 NA NA E 4 7 9 10 NA See ?read.table for more information on the file reading part. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question: reading lower triangular matrix
This has been answered at the following URL http://tolstoy.newcastle.edu.au/~rking/R/help/04/11/6695.html On Tue, 2005-07-12 at 14:37 -0300, Rogério Rosa da Silva wrote: Dear list, I will like to learn how to read a lower triangular matrix in R. The input file *.txt have the following format: A B C D E A 0 B 10 C 250 D 3680 E 479 100 How this can be done? Thanks in advance for your help Rogério __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question: reading lower triangular matrix
Dear Adaikalavan and Marc, Thanks for advices. The answer in R-help archives is exactly what I'm needing. Best regards, Rogério Adaikalavan Ramasamy wrote: This has been answered at the following URL http://tolstoy.newcastle.edu.au/~rking/R/help/04/11/6695.html On Tue, 2005-07-12 at 14:37 -0300, Rogério Rosa da Silva wrote: __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] simple question, i hope
How do you output a list to a text file without the extra line numbers and stuff? I have a list b, and tried zz-textConnection(captest.txt,w) sink(zz) b sink() close(zz) but that isnt what i want, because i get [[1]] [1] a etc. Is there a simple way to do the R equivalent of this perl code? open(OUT,out.txt); print OUT @b; close OUT Thank you for your help. I tried pouring over teh documentation for this, but couldnt find what I was lookign for. ~Erithid __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] simple question on graphics window
Dear All, This is a rather simple question. How do I open more than 1 graphics window? Dom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on graphics window
Dom Peters wrote: Dear All, This is a rather simple question. How do I open more than 1 graphics window? See ?x11 Uwe Ligges Dom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on graphics window
Le 26.04.2005 11:36, Dom Peters a écrit : Dear All, This is a rather simple question. How do I open more than 1 graphics window? Dom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html *REALLY DO IT ** ?x11 ?windows -- ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on picking out some rows of a matrix/data frame
On Mon, 9 Feb 2004, Roger Levy wrote: Hi, I have a simple question about matrix/data frame manipulation. I have a data frame that looks a something like this XYZ 10apples -1 -1 oranges ... 0-1 bananas and I'd like to pull out all the rows for which X and Y are (un)equal into a submatrix. subset(the.data.frame, X!=Y) -thomas __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on picking out some rows of a matrix/data frame
Have you looked at subset? eg subset(dataframe, x != y, select = c(x, y)) Hadley Roger Levy wrote: Hi, I have a simple question about matrix/data frame manipulation. I have a data frame that looks a something like this XYZ 10apples -1 -1 oranges ... 0-1 bananas and I'd like to pull out all the rows for which X and Y are (un)equal into a submatrix. How can I do that? Many thanks, Roger Levy __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on picking out some rows of a matrix/data frame
subset will do the selection. If you really want a matrix for the result you will need to coerce it using as.matrix. Roger Levy [EMAIL PROTECTED] writes: I have a simple question about matrix/data frame manipulation. I have a data frame that looks a something like this XYZ 10apples -1 -1 oranges ... 0-1 bananas and I'd like to pull out all the rows for which X and Y are (un)equal into a submatrix. How can I do that? Many thanks, Roger Levy __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] simple question on picking out some rows of a matrix/data frame
One alternative that I use is illustrated in the following examples: DF[DF$x==DF$y, ] x y z 1 -1 -1 a 4 1 1 d sel - (DF$x != DF$y) DF[sel,] x y z 2 1 -1 b 3 -1 1 c hope this help. spencer graves Douglas Bates wrote: subset will do the selection. If you really want a matrix for the result you will need to coerce it using as.matrix. Roger Levy [EMAIL PROTECTED] writes: I have a simple question about matrix/data frame manipulation. I have a data frame that looks a something like this XYZ 10apples -1 -1 oranges ... 0-1 bananas and I'd like to pull out all the rows for which X and Y are (un)equal into a submatrix. How can I do that? Many thanks, Roger Levy __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Simple question about export
Hi, Sorry about making this stupid question, but I did not find the answer from documentation. I managed to read my spss .sav file into the R, no problem. Next I would like to write this data to a file in ascii-format. I tried to use write.table and I got no error messages, but no file either. What is the right way to make it? At least write.table(c:\foo\data.dat) does not work.. Thanks in advance! Michael = [EMAIL PROTECTED] +358 40 849 1140 __ Yahoo! Web Hosting - establish your business online __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Simple question about export
On Wed, 12 Mar 2003, Michael Miettinen wrote: Sorry about making this stupid question, but I did not find the answer from documentation. See the FAQ question 7.10 How do file names work in Windows? I managed to read my spss .sav file into the R, no problem. Next I would like to write this data to a file in ascii-format. I tried to use write.table and I got no error messages, but no file either. What is the right way to make it? At least write.table(c:\foo\data.dat) does not work.. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Simple question about export
Well, you did not specify the object to save in write.table(). Suppose you want to save the following: x - matrix( c(1:25), nrow=5) write.table(x, file=c:/my.output.file.txt) If all goes well, you should see the prompt without any message. Also use / rather than \ as it is reserved for escape sequences. You might also consider setting the option sep=\t and quote=FALSE to make it truly tab-delimited file. There is also row.names, col.name option. Try reading the R Data Import/Export or write.table() again. -Original Message- From: Michael Miettinen [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 12, 2003 9:13 PM To: [EMAIL PROTECTED] Subject: [R] Simple question about export Hi, Sorry about making this stupid question, but I did not find the answer from documentation. I managed to read my spss .sav file into the R, no problem. Next I would like to write this data to a file in ascii-format. I tried to use write.table and I got no error messages, but no file either. What is the right way to make it? At least write.table(c:\foo\data.dat) does not work.. Thanks in advance! Michael = [EMAIL PROTECTED] +358 40 849 1140 __ Yahoo! Web Hosting - establish your business online __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Simple question about export
If that is what you tried, then you didn't supply the object to the write.table function. e.g. if your data.frame is called mydata in R you need write.table(mydata,c:/foo/data.dat) The file is ascii. Note also that you either have to use forward slashes (as above) or double backslashes write.table(mydata,c:\\foo\\data.dat) R doesn't do the expected thing with single backslashes as you wrote it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Michael Miettinen Sent: 12 March 2003 15:13 To: [EMAIL PROTECTED] Subject: [R] Simple question about export Hi, Sorry about making this stupid question, but I did not find the answer from documentation. I managed to read my spss .sav file into the R, no problem. Next I would like to write this data to a file in ascii-format. I tried to use write.table and I got no error messages, but no file either. What is the right way to make it? At least write.table(c:\foo\data.dat) does not work.. Thanks in advance! Michael = [EMAIL PROTECTED] +358 40 849 1140 __ Yahoo! Web Hosting - establish your business online __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Simple question about export
- Original Message - From: Michael Miettinen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, 12 March, 2003 2:13 PM Subject: [R] Simple question about export Hi, Sorry about making this stupid question, but I did not find the answer from documentation. I managed to read my spss .sav file into the R, no problem. Next I would like to write this data to a file in ascii-format. I tried to use write.table and I got no error messages, but no file either. What is the right way to make it? At least write.table(c:\foo\data.dat) does not From the rw-FAQ: Backslashes have to be doubled in R character strings: write.table(x, c:\\foo\\data.dat) or use a forward slash: write.table(x, c:/foo/data.dat) where x is your data object Mathieu Roelants, Project Vlaamse Groeicurven[EMAIL PROTECTED] Laboratorium Antropogenetica Vrije Universiteit Brussel, Pleinlaan 2, B-1050 Brussel Tel.+Fax 02/629.34.07 Laboratory of Anthropogenetics - University of Brussels, Pleinlaan 2, B-1050 Brussels (Belgium) Tel.+Fax + 32 2 629 34 07 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help