[R] nls model definition help
Hi fellow R users, I'm trying to fit a model using nls with the following model definition: y(t+1)=(th1*x1 + R1*x2) * exp(a1*x3) + (1-th1*x1 + R1*x2)*y(t) y is the dependent variable (note on both sides of eq) and the x's represent the regressors. th1, R1 and a1 are parameters to be estimated. The problem is non- linear and hence why I'm trying to fit using the well used nls function. To fit the model I would like to be able to use the formula interface rather than build my own ugly function definition. Any ideas if this is achievable and if not any ideas on how to fit this model? Many thanks, Wayne Wayne Jones Statistics Chemometrics Shell Global Solutions (UK) Shell Technology Centre Thornton P.O. Box 1, Chester CH1 3SH, United Kingdom Tel: +44 (0) 151 373 5977 Mobile: +44 (0) 7896 536026 Email: wayne.w.jo...@shell.commailto:wayne.w.jo...@shell.com Intranet: Statistics and Chemometrics - Shell Wikihttp://sww.wiki.shell.com/wiki/index.php/Statistics_and_Chemometrics Internet: Shell Global Solutionshttp://www.shell.com/globalsolutions Shell Global Solutions (UK) is a division of Shell Research Limited which has its Registered Office at Shell Centre, London SE1 7NA and is registered in England Wales with No.539964. [[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] function for special matrix design
Lookup: ?diag ?upper.tri ?lower.tri Example: my.mat-matrix(1:16,ncol=4) my.mat my.mat[upper.tri(my.mat)]-3 my.mat -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of kevinchang Sent: 01 October 2007 17:37 To: r-help@r-project.org Subject: [R] function for special matrix design Hi All, I am trying to make a matrix with a particular value for all the elements above and including diagonal and another particular value for all the elements below diagonal. Obviously , Matrix function in Matrix package does not work since it only allow filling by either row or column. So I am wondering if there is a built-in function allowing me to do this ? please help. Thanks -- View this message in context: http://www.nabble.com/function-for-special-matrix-design-tf4549437.html#a12982709 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] 3-dimensional graph
Hi there, you could try: library(scatterplot3d) THese function are also quite handu for visualising 3d images in 2d by virtue of contours, heat maps etc.. ?image ?persp ?contour -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Sorkin Sent: 01 October 2007 03:46 To: r-help@r-project.org Subject: [R] 3-dimensional graph Windows XP R 2.3.1 I have a funciton fit1-lm(y~x+z) Is there a function that will produce a 3-dimensional plot of y,x,z? I looked at the help files, but did not find a clean answer to my question. Thanks, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the =\...{{dropped}} __ 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] Concatenating one character vector into one string
x - c(This , is , one , sentence.) paste(x,collapse=) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Rainer M. Krug Sent: 01 October 2007 13:23 To: r-help Subject: [R] Concatenating one character vector into one string Hi I am sure this is simple - but how can I convert one charecter vector into one string? example: x - c(This , is , one , sentence.) should become This is one entence Thanks Rainer -- NEW EMAIL ADDRESS AND ADDRESS: [EMAIL PROTECTED] [EMAIL PROTECTED] WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel:+27 - (0)21 650 5776 (w) Fax:+27 - (0)86 516 2782 Fax:+27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ 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] xyplot
When you call xyplot in a for loop you have to use the print command. For instance modifying the xyplot example: The following wont work: Depth - equal.count(quakes$depth, number=8, overlap=.1) for(i in 1:3){xyplot(lat ~ long | Depth, data = quakes)} But this will: for(i in 1:3){print(xyplot(lat ~ long | Depth, data = quakes))} Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Samor Gandhi Sent: 01 October 2007 15:20 To: [EMAIL PROTECTED] Subject: [R] xyplot Hello, I am calling the following code with the loop! It makes 3 out graphs but empty! COuld you help me plase on that? Thank you in advance z1 - dbConnect(MyData, something, A1, A2) for (tt in c(xyz, abc, m1)) { message(paste(Here, tt, !!!)) mydata - dbReadTable(z1, tt) jpeg(file=paste(D:/, tt, .jpg, sep=), width=00, height=100) plot.method=bitmap xyplot(MyVALUE ~ MyNo | as.character(ID), data = mydata, main = tt, xlab = , ylab = , type=l) dev.off() } - [[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] Need help with function writing
Why dont you use the t.test within R? See help(t.test). It looks to have everything you need: here are the examples with different alternative hypothesese: with(sleep, t.test(extra[group == 1], extra[group == 2],alternative = greater)) with(sleep, t.test(extra[group == 1], extra[group == 2],alternative = two.sided)) with(sleep, t.test(extra[group == 1], extra[group == 2],alternative = less)) If you are still really keen to use your own function I would use help(switch) to select between different alternative hypths. Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Letticia Ramlal Sent: 25 September 2007 14:20 To: [EMAIL PROTECTED] Subject: [R] Need help with function writing Hello: If anyone could guide me with this I would greatly appreciate it. Thanking you in advance for your assistance. Using a 3-level input factor alternative so that a function(below) can compute both a two-sided and one-sided p-values. Making the two-sided test the default. And produce output information about which alternative was tested. Where would I place the ifelse statement? function(yvec,trtvec,alpha=0.05,header=) { # # A function to compute a two-sample t-test and confidence # interval (equal-variance, independent samples). yvec is # a numeric vector containing both samples' data. trtvec # is a vector, same length as yvec, of treatment # identifiers for the data in yvec. A boxplot comparing # the treatments' data is constructed. Output is a one-row # data frame reporting the results of the test and # confidence interval ## trtvec=as.factor(trtvec) boxplot(split(yvec,trtvec)) title(header) ybar=tapply(yvec,trtvec,mean) varvec=tapply(yvec,trtvec,var) nvec=table(trtvec) error.df=nvec[1]+nvec[2]-2 pooled.var=((nvec[1]-1)*varvec[1]+(nvec[2]-1)*varvec[2])/error.df diff12estimate=ybar[1]-ybar[2] stderr=sqrt(pooled.var*((1/nvec[1])+(1/nvec[2]))) tratio=diff12estimate/stderr twosidedP=2*(1-pt(abs(tratio),error.df)) tcrit=qt(1-alpha/2,error.df) lower=diff12estimate-tcrit*stderr upper=diff12estimate+tcrit*stderr calpha=1-alpha out=data.frame(diff12estimate,stderr,tratio,twosidedP,lower,upper,alpha) names(out)=c(Estimator,SE,T,P-value,Lower CI,Upper CI,Confidence) out } __ 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] RODBC problem
Not sure which of the questions yo want answered in your email. However, if its the one regarding the boxplot try: dd - read.table(test.txt,header=T) attach(dd) boxplot(x) outlier - function(y){ out - boxplot(y, range = 1)$out outliers - which(y %in% out) return(list(out=out,outliers=outliers)) } outlier(x) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of amor Gandhi Sent: 26 September 2007 11:45 To: DUPREZ Cédric; Bernhard Wellhöfer Cc: [EMAIL PROTECTED] Subject: Re: [R] RODBC problem Hello, I wrote setwd(D:/) dd - read.table(file=test.txt,header=TRUE) attach(dd) boxplot(x) outlier - function(y){ + out - boxplot(y, range = 1)$out + outliers - which(y == out) + dev.off() + return(out,outliers) + } outlier(x) $out [1] 1.950208 2.082025 4.768637 4.800333 5.529516 1.657321 4.656504 2.138956 [9] 4.437906 4.716786 $outliers [1] 23 Warning messages: Could you tell me please why do I have Warning messages and why I do not get all the id for the outliers in out, but only for the id=23? Thank you very much in advance! Amor DUPREZ Cédric [EMAIL PROTECTED] schrieb: Hello, The problem seems to be in the query syntax. Can you show us the query you are trying to perform ? Regards, Cedric -Message d'origine- De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Bernhard Wellhöfer Envoyé : vendredi 6 juillet 2007 11:45 À : [EMAIL PROTECTED] Objet : [R] RODBC problem Hello, I use a RODBC connection to a MySQL server on a Debian machine. The call to odbcConnect() seems to be ok, but the result of the first sqlFetch(channel,t_studie) retrieves this data frame: [1] [RODBC] ERROR: Could not SQLExecDirect [2] 42000 1064 [MySQL][ODBC 3.51 Driver][mysqld-5.0.22-Debian_1bpo1-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\t_studi(\004 Please note the funny character at the end of the table name in the error message. The Test Data Source option on the ODBC Data Source Name configuration panel report success. Who can help me here? Regards, Bernhard [[alternative HTML version deleted]] __ [EMAIL PROTECTED] 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. __ [EMAIL PROTECTED] 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] finding a stable cluster for kmeans
Hi there, If the final predicted clusters vary according to a random starting cluster then I suspect that your data is not clustering very well!! A few reasons for this may be: 1) There are genuinely no clusters in the data! 2) You have chosen a poor distance measure. 3) You have picked an inappropriate number of clusters. The basic goodness of fit of a cluster is that the variance within a cluster is small and the variance between clusters is large. Whenever I start to look for clusters I often use multidimensional scaling to look at the data in 2D! Lookup help(cmdscale) If after this you wish to proceed, then I suggest you look up the library(cluster). The function silhouette is a nice tool to assess the appropriate number of clusters. Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Julia Kröpfl Sent: 25 September 2007 10:01 To: R-help@r-project.org Subject: [R] finding a stable cluster for kmeans Hallo! I applied kmeans to my data: kcluster= kmeans((mydata, 4, iter.max=10) table(code, kcluster$cluster) If I run this code again, I get a different result as with the first trial (I understand that this is correct, since kmeans starts randomly with assigning the clusters and therefore the outcomes can be different) But is there a way to stabilize the cluster (meaning finding the one cluster that appears the most often in 10 trials)? Thank you for any ideas, Julia -- __ 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] Logistic regression
Google search Logistic Regression using R There are loads of good links here. Basically you use a generalized linear model. Look up ?glm Regards Wayne -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of martin pareja Sent: 13 September 2007 16:33 To: r-help@r-project.org Subject: [R] Logistic regression Hello I am trying to get the estimated value of logit(p), along with its standard error/conf interval from a logistic regression model (for the overall sample, and for individual treatment levels), where p is the proportion of successes. I am having difficulty in finding how to tell R to give this information. Would anybody be able to help with this? Thanks Martin Pareja __ 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] Comparing regression models
I would suggest doing an F-test.A descrition is given here: http://www.graphpad.com/curvefit/2_models__1_dataset.htm. The method is valid becasue one of your models is a subset of another. Correct use of the anova function does indeed perform this test. For example: data(airquality) lm1-lm(Ozone~.,airquality) # full model lm2-lm(Ozone~Solar.R+Wind +Month+Day,airquality) # reduced model anova(lm2,lm1) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: 14 September 2007 15:49 To: r-help@r-project.org Subject: [R] Comparing regression models Dear list, I am interested in comparing two linear regression models to see if including one extra variable improves the model significantly. I have read that one possibility is doing an F test on the goodness-of-fit values for both models, and another option that is comparing the residuals of both models using a paired test. I also know about the anova() function that compares results for two models but am not sure what it actually does compare. Can you give me any suggestions? Does the same hold if the models were logistic instead of linear? I have read that the Akaike´s AIC is also a valid option. Thanks in advance for your comments David __ 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.