[R] Extract Coeff, Std Error, etc from gnls output
Dear list members; Is there any trick to extract the coefficients along with std errors, t-values and p-values for each beta from a gnls fit model (similar to the results obtained using summary(lm)$coeff for linear models)? Thanks for any hint cm __ 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] error in gnls
Dear R users; I'm trying to fit nonlinear model (asymptotic regression model) with gnls from library nlme in R 2.1.0 with no big issues so far. However after installed the version R 2.1.1, when I tried to update the initial model including a var-cov model I've got the error: "Error: Object "convIter" not found". This error occurs only with R 2.1.1. Any ideas? Thanks Christian Mora __ 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] nlme questions
Dear R users; Ive got two questions concerning nlme library 3.1-65 (running on R 2.2.0 / Win XP Pro). The first one is related to augPred function. Ive been working with a nonlinear mixed model with no problems so far. However, when the parameters of the model are specified in terms of some other covariates, say treatment (i.e. phi1~trt1+trt2, etc) the augPred function give me the following error: "Error in predict.nlme(object, value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not allowed for trt1, trt2". The same model specification as well as the augPred function under SPlus 2000 run without problems. The second question has to deal with the time needed for the model to converge. It really takes a lot of time to fit the model on R in relation to the time required to fit the same model on SPlus. I can imagine this is related to the optimization algorithm or something like that, but I would like to have a different opinion on these two issues. Thanks in advance Christian Mora __ 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] nlme questions
Spencer; Thanks for your suggestions. I found the problem is in the library nlme. If you define phi1~factor(trt1)+factor(trt2) instead of phi1~trt1+trt2 the augPred function works. A bug? I don't know. Christian Spencer Graves <[EMAIL PROTECTED]> on 17-11-2005 20:19:32 To: Christian Mora <[EMAIL PROTECTED]> cc:r-help@stat.math.ethz.ch Subject:Re: [R] nlme questions Both your questions seem too vague to me. You might get more useful replies if you provide a simple example in a few lines of R code that a reader could copy from your email into R and see the result (as suggested in the posting guide! "www.R-project.org/posting-guide.html"). The process of preparing such a simple example might by itself provide the insight you desire. Alternatively, you might work line by line through the code for the R function you are using. Also, if you don't have Pinheiro and Bates (2000) Mixed-Effects Models in S and S-PLUS (Springer), I suggest you get it; it is excellent for things like this. I'm sorry I couldn't help more. spencer graves Christian Mora wrote: > > > > Dear R users; > > Ive got two questions concerning nlme library 3.1-65 (running on R 2.2.0 / > Win XP Pro). The first one is related to augPred function. Ive been working > with a nonlinear mixed model with no problems so far. However, when the > parameters of the model are specified in terms of some other covariates, > say treatment (i.e. phi1~trt1+trt2, etc) the augPred function give me the > following error: "Error in predict.nlme(object, > value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not allowed for trt1, > trt2". The same model specification as well as the augPred function under > SPlus 2000 run without problems. The second question has to deal with the > time needed for the model to converge. It really takes a lot of time to fit > the model on R in relation to the time required to fit the same model on > SPlus. I can imagine this is related to the optimization algorithm or > something like that, but I would like to have a different opinion on these > two issues. > > Thanks in advance > > Christian Mora > > __ > 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 -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA [EMAIL PROTECTED] www.pdf.com <http://www.pdf.com> Tel: 408-938-4420 Fax: 408-280-7915 __ 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] nlme questions
Yes, I agree. But if you define at the beginning of the code: data$trt1<-as.factor(data$trt1) data$trt2<-as.factor(data$trt2) being trt1 and trt2 dummy variables with values 0 or 1, and then run the model, for instance: fit_1<-nlme(Y~b0/(1+exp((b1-X)/b2)),fixed=b0+b1+b2~trt1+trt2, random=b0+b1+b2~1,data=data,start=fixef(fit_0)) the augPred function doesn't work and return the error "Error in predict.nlme(object, value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not allowed for trt1, trt2" but, if you modify the code as fit_2<-nlme(Y~b0/(1+exp((b1-X)/b2)),fixed=b0+b1+b2~factor(trt1)+factor(trt2), random=b0+b1+b2~1,data=data,start=fixef(fit_0)) i.e. indicating again that trt1 and trt2 are factors, even when they were previouslly defined as factors through the function "as.factors", then augPred works "Austin, Matt" <[EMAIL PROTECTED]> on 18-11-2005 07:19:24 To:"'Christian Mora'" <[EMAIL PROTECTED]>, Spencer Graves <[EMAIL PROTECTED]> cc:r-help@stat.math.ethz.ch Subject:RE: [R] nlme questions Warning: non-expert thoughts to follow. When passing an object to a predict method, the method looks at (a copy) of the original information from the dataframe that was used in the fit. Your original data contains information on trt1 and trt2, but factor(trt1) and factor(trt2) cannot be found in the original data. If you did the factor conversion in the original data myDat <- factor(myDat$trt1) myDat <- factor(myDat$trt2) then used myDat as the dataframe in the nlme call, all information would be available for the augPred method. That's why it works when you use trt1 and trt2 instead of factor(trt1) and factor(trt2). There is actually an implicit factor conversion happening in the nlme call if trt1 and trt2 are character variables, however if trt1 and trt2 are defined as numeric (ie 0 1) then it will fit as a numeric. --Matt > -----Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Christian Mora > Sent: Friday, November 18, 2005 4:01 AM > To: Spencer Graves > Cc: r-help@stat.math.ethz.ch > Subject: Re: [R] nlme questions > > > > > > > > Spencer; > > Thanks for your suggestions. I found the problem is in the > library nlme. If > you define phi1~factor(trt1)+factor(trt2) instead of > phi1~trt1+trt2 the > augPred function works. A bug? I don't know. > > Christian > > > > > > > Spencer Graves <[EMAIL PROTECTED]> on 17-11-2005 20:19:32 > > To:Christian Mora <[EMAIL PROTECTED]> > cc:r-help@stat.math.ethz.ch > > Subject:Re: [R] nlme questions > > >Both your questions seem too vague to me. You might get > more useful > replies if you provide a simple example in a few lines of R > code that a > reader could copy from your email into R and see the result (as > suggested in the posting guide! > "www.R-project.org/posting-guide.html"). > The process of preparing such a simple example might by > itself provide > the insight you desire. Alternatively, you might work line by line > through the code for the R function you are using. Also, if you don't > have Pinheiro and Bates (2000) Mixed-Effects Models in S and S-PLUS > (Springer), I suggest you get it; it is excellent for things > like this. > >I'm sorry I couldn't help more. >spencer graves > > Christian Mora wrote: > > > > > > > > > Dear R users; > > > > Ive got two questions concerning nlme library 3.1-65 > (running on R 2.2.0 > / > > Win XP Pro). The first one is related to augPred function. Ive been > working > > with a nonlinear mixed model with no problems so far. > However, when the > > parameters of the model are specified in terms of some > other covariates, > > say treatment (i.e. phi1~trt1+trt2, etc) the augPred > function give me the > > following error: "Error in predict.nlme(object, > > value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not > allowed for trt1, > > trt2". The same model specification as well as the augPred > function under > > SPlus 2000 run without problems. The second question has to > deal with the > > time needed for the model to converge. It really takes a > lot of time to > fit > > the model on R in relation to the time required to fit the > same model on > > SPlus. I can imagine this is related to the optimization > algorithm or > > something like that, but I would like to have a different opinion on > these > > two issues. > > > > Thanks in advance > > > > Christian Mora > > > > _
RE: [R] Tutorial for graphics
A fairly good tutorial is Gráficos Estadísticos con R by Juan Carlos Correa and Nelfi González (PDF [2110kB]) that you can find in Documentation/Contributed (in Spanish though). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Phil Sent: Wednesday, June 16, 2004 10:13 PM To: [EMAIL PROTECTED] Subject: [R] Tutorial for graphics Hi all, I'm coming to R from Matlab and I'm finding it difficult to find a good introduction to graphics in R. (The best I've found so far is Ch. 4 of Emmanuel Paradis "R for Beginners". Still, I have been unable to discover simple things like how to resize the axes on an existing plot, how to add (or change) axis labels on an existing plot, etc. Can anyone point me to a suitable tutorial, or even tell me how to perform those tasks? Also, Matlab's graphical widget has the ability to zoom (and unzoom) by drawing a rectangle on the graph with the mouse. Is there anything similar in R? Thanks in advance, Phil Morenz __ [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] intersect two files
Hi all; Im working with two datasets in R, say data1 and data2. Both datasets are composed of several rows and columns (dataframe) and some of the rows are identical in both datasets. Im wondering if there is any way to remove from one set, say data1, the rows that are identical in the other set, say data2, using R? Thanks for any hint in advance Christian __ [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
RE: [R] covariate selection?
Hi Ian Have you tried help.search("pca")? Christian -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Martínez Ovando Juan Carlos Sent: Tuesday, October 12, 2004 7:56 PM To: Ian Fiske Cc: [EMAIL PROTECTED] Subject: RE: [R] covariate selection? Hello Ian, Sorry. I don't really understand your problem, which is of model selection. That's right? You could use some criteria based in likelihood. For instante Akaike (AIC) or Schwarz criteria (BIC), see: ?AIC ?mle.aic (The best model is determined minimizing AIC or BIC). I hope this help you. Greetings, Juan Carlos -Mensaje original- De: Ian Fiske [mailto:[EMAIL PROTECTED] Enviado el: Martes, 12 de Octubre de 2004 05:17 PM Para: Martínez Ovando Juan Carlos CC: [EMAIL PROTECTED] Asunto: Re: [R] covariate selection? Thanks Juan. I thought that was what I was looking for, but really, I want to know which of the original covariates could best be used to take advantage of their colinearity without creating new variables. I think PCA creates new variables. SAS and SPSS can do what I'm talking about, but I would like to use R for this. Thanks, Ian Martínez Ovando Juan Carlos wrote: >Hello Ian, > >?princomp > >If your covariates are scalars, and the following documents: > >http://www.jstatsoft.org/v07/i01/drdoc.pdf > >http://www.bioconductor.org/workshops/Milan/PDF/Lab12.pdf > > >Best wishes. > >Saludos, > >Juan Carlos Martínez Ovando >Banco de México >Av. 5 de Mayo No. 18 >Piso 5 Sección D >Col. Centro >06059 México, D. F. >Tel. +52 55 52.37.20.00 ext. 3594 >Fax. +52 55 52.37.27.03 >e-mail: [EMAIL PROTECTED] > > >-Mensaje original- >De: Ian Fiske [mailto:[EMAIL PROTECTED] >Enviado el: Martes, 12 de Octubre de 2004 04:08 PM >Para: [EMAIL PROTECTED] >Asunto: [R] covariate selection? > >Hello, > >I am hoping someone can help me with the following multivariate issue: >I have a model consisting of about 50 covariates. I would like to >reduce this to about 5 covariate for the reduced model by combining >cofactors that are strongly correlated. Is there a package or function >that would help me with this in R? I appreciate any suggestions. > >Thanks, >Ian > >__ >[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 > > > > __ [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 __ [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
RE: [R] Sampling
YourData[sample(209,106),] Regards Christian Mora -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Savano Sent: Monday, December 01, 2003 9:38 AM To: Lista R Subject: [R] Sampling UseRs, I imported a table using "read.table". It has 209 observations, I want to select a sample with 106 observations. What function I use? thanks. __ [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
[R] Johnson's Sb distribution
Hi all; I'm working with the library SuppDists trying to fit a Johnson's Sb distribution to a dataset. It works fine, but I need to set one of the location parameters (epsilon) to zero. How can I do this using the function JohnsonFit() or any other similar? ...and Is it possible to define the type (SN,SL,SB,SU) or the library assumes the type automatically depending on the data? Thanks for any hint Christian __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] mode
How can I get the mode (most frequent value) from a dataset (continuos variables)? I can obtain it when the data is discrete (by making a table and looking at the higher frequency) but I don't know how obtain it from, for example, a density plot of the data. Does anyone know how to do it? Thanks CM __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] 4-parameter logistic model
Dear R users I'm a new user of R and I have a basic question about the 4-parameter logistic model. According to the information from Pinheiro & Bates the model is: y(x)=theta1+(theta2-theta1)/(1+exp((theta3-x)/theta4)) == y(x)=A+(B-A)/(1+exp((xmid-input)/scal)) from the graph in page 518 of the book of the same authors (mixed models in S) theta 1 corresponds to the horizontal asymptote as x goes to infinity and theta2 the horizontal asymptote as x goes to -infinity. When I use the function SSfpl(input,A,B,xmid,scal), I'm not sure why the value of A is the lower of the two asymptotes if according to the original function A should be equal to theta1 (upper asymptote).. or maybe I'm wrong. I'll appreciate any comment on this. Best Regards CM __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Lattice graphs and legend
Dear all, I'm working with grouped data using the nlme package in R. By using the function plot() I'm trying to obtain a trellis-like graph but by default a legend is placed on top of the plot. How can I remove this legend? Thanks for any hint Christian Mora __ Yahoo! SiteBuilder - Free, easy-to-use web site design software __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Question about 'NA'
Hi all, Ive got a database with 10 columns (different variables) for 100 subjects, each column with different # of NA's. I'd like to know if it is possible to use a function to exclude the NA's using only a specific column, lets say: Data2 <- omit.exclude(Data1$column1) ??, then Data3 <- omit.exclude(Data1$column2) and so on I tried the code above but with no results Thanks for any help CM __ Yahoo! SiteBuilder - Free, easy-to-use web site design software __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] gnls - Step halving....
Hi all, I'm working with a dataset from 10 treatments, each treatment with 30 subjects, each subject measured 5 times. The plot of the dataset suggests that a 3-parameter logistic could be a reasonable function to describe the data. When I try to fit the model using gnls I got the message 'Step halving factor reduced below minimum in NLS step'. I´m using as the initial values of the parameters those obtained from the nls fit. Is a problem of the initial estimates of the parameters that I get the error or could be something else? The code for the nls fit was: options(contrasts=c("contr.helmert","contr.poly")) VA1.lis<-nlsList(DRAM~SSlogis(MED,phi1,phi2,phi3)|TRAT, data=VA1,na.action=na.omit) The code for the gnls fit was (using a 'difference parameterization' like SAS): options(contrasts=c("contr.SAS","contr.poly")) VA1.gnls<-gnls(DRAM~SSlogis(MED,phi1,phi2,phi3), data=VA1,params=list(phi1~TRAT,phi2~TRAT,phi3~TRAT), start=c( 23.36209, avg of phi1 for the 10 trts * -0.8549794, * diff. between avg and nls estimate of TRAT#2 ** .and so on I´d appreciate any comment Thanks CM __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] gnls - Step halving....
Hi all, I'm working with a dataset from 10 treatments, each treatment with 30 subjects, each subject measured 5 times. The plot of the dataset suggests that a 3-parameter logistic could be a reasonable function to describe the data. When I try to fit the model using gnls I got the message 'Step halving factor reduced below minimum in NLS step'. I´m using as the initial values of the parameters those obtained from the nls fit. Is a problem of the initial estimates of the parameters that I get the error or could be something else? The code for the nls fit was: options(contrasts=c("contr.helmert","contr.poly")) VA1.lis<-nlsList(DRAM~SSlogis(MED,phi1,phi2,phi3)|TRAT, data=VA1,na.action=na.omit) The code for the gnls fit was (using a 'difference parameterization' like SAS): options(contrasts=c("contr.SAS","contr.poly")) VA1.gnls<-gnls(DRAM~SSlogis(MED,phi1,phi2,phi3), data=VA1,params=list(phi1~TRAT,phi2~TRAT,phi3~TRAT), start=c( 23.36209, avg of phi1 for the 10 trts * -0.8549794, * diff. between avg and nls estimate of TRAT#2 ** .and so on I´d appreciate any comment Thanks CM __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] custom loss function + nonlinear models
Hi all; I'm trying to fit a reparameterization of the assymptotic regression model as that shown in Ratkowsky (1990) page 96. Y~y1+(((y2-y1)*(1-((y2-y3)/(y3-y1))^(2*(X-x1)/(x2-x1/(1-((y2-y3)/(y3-y1))^2)) where y1,y2,y3 are expected-values for X=x1, X=x2, and X=average(x1,x2), respectively. I tried first with Statistica v7 by LS and Gauss-Newton algorithm without success (no convergence: predictors are redundant). Then I tried with the option CUSTOM LOSS FUNCTION and several algorithms like Quasi-Newton, Simplex, Hookes-Jeeves, among others. In all these cases the model converged to some values for the parameters in it. My question is (after searching the help pages) : Is there such a thing implemented in R or can it be easily implemented? In other words, is it possible to define which loss function to use and the algorithm to find the parameters estimates? Thanks Christian __ 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] Non-Linear Regression Problem
Working on the same idea, Ive generated a data grid with 4 vars, two of them with its own sequence and two with fixed values. As Spencer pointed out one option is to get the values from a simple loop. My question is: How can jump from one set of starting values to the next (on the data grid) in case they cause an invalid value in the model Im evaluating? In my example, Ive 12 possible combinations of the 4 vars and in the 6th combination I get an error and the loop is terminated so what Im looking for is to skip this problem and continue from the 7th to 12th combination of starting points Ill appreciate any comment Code: data<-expand.grid(alpha=100,delta=4,beta=seq(1,2,by=0.5),gamma=seq(.1,.4 ,by=.1)) for(i in 1:12){ fit<-nls(y~delta+(alpha-delta)/(1+exp(beta*log(rate/gamma))),data=base,s tart=c(alpha=data$alpha[i],delta=data$delta[i],beta=data$beta[i],gamma=d ata$gamma[i]),trace=T) } Thanks CMora -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Spencer Graves Sent: Wednesday, April 14, 2004 12:27 PM To: WilDscOp Cc: [EMAIL PROTECTED] Subject: Re: [R] Non-Linear Regression Problem 1. For the equation you mentioned, have you considered the following: DF <- data.frame(t.=c(1, 4, 16), Y=c(.8, .45, .04)) # I do NOT use "t" as a name, as it # may conflict with the matrix transpose function. fit0 <- lm(log(Y)~t.-1, DF) fit0 Call: lm(formula = log(Y) ~ t. - 1, data = DF) Coefficients: t. -0.2012 If this is the problem you really wanted to solve AND you honestly need NONLINEAR least squares, I would expect that (-0.2) should provide a reasonable starting value for nls: > fit1 <- nls(Y~exp(-THETA*t.), data=DF, start=c(THETA=-0.2)) > fit1 Nonlinear regression model model: Y ~ exp(-THETA * t.) data: DF THETA 0.2034489 residual sum-of-squares: 0.0003018337 > 2. Alternatively, you could compute the sum of squares for all values of THETA = seq(0, .01, 100) in a loop, then find the minimum by eye. 3. If this is just a toy example, and your real problem has several parameters, "expand.grid" will produce a grid, and you can compute the value of your function and the sum of squares of residuals at every point in the grid in a single loop, etc. hope this helps. spencer graves WilDscOp wrote: > Dear all, > > I was wondering if there is any way i could do a "Grid Search" on > a parameter space using R (as SAS 6.12 and higher can do it) to start > the Newton-Gauss Linearization least squares method when i have NO > prior information about the parameter. > W. N. Venables and B. D. Ripley (2002) "Modern Applied Statistics with > S", 4 th ed., page 216-7 has a topic "Self-starting non-linear > regressions" using negexp.SSival - but i can not solve my hypothetical > problem using that - my problem is : > > Y = EXP(-(THETA * t)) with data below for estimating THETA: > > tY > 10.80 > 4 0.45 > 16 0.04 > > Whatever i could do, is in > http://www.angelfire.com/ab5/get5/nonlinear.PDF > > Any response / help / comment / suggestion / idea / web-link / replies > will be greatly appreciated. > > Thanks in advance for your time. > > ___ > > Mohammad Ehsanul Karim <[EMAIL PROTECTED]> > Institute of Statistical Research and Training > University of Dhaka, Dhaka- 1000, Bangladesh > > __ > [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 __ [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