[R] question about non-linear least squares in R
Hi, everyone, My question is: It's not every time that you can get a converged result from the nls function. Is there any solution for me to get a reasonable result? For example: x - c(-0.06,-0.04,-0.025,-0.015,-0.005,0.005,0.015,0.025,0.04,0.06) y - c(1866760,1457870,1314960,1250560,1184850,1144920,1158850,1199910,1263850,1452520) fitOup- nls(y ~ constant + A*(x-MA)^4 + B*(x-MA)^2, start=list(constant=1000, A=1, B=-100, MA=0), control=nls.control(maxiter=100, minFactor=1/4096), trace=TRUE) For this one, I cannot get the converged result, how can I reach it? To use another funtion or to modify some settings for nls? Thank you very much! Yours, Warren __ 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] difftime for handling time units--hours, minutes, days--from file times
Thanks, Tim To get the time difference in the proper units, it's as simple as this: difftime(myfileinfo$mtime[2], myfileinfo$mtime[1], units=hours) Cheers, Warren On 11/13/06, Tim Calkins [EMAIL PROTECTED] wrote: hardly the most efficient way to go, but consider using a substring function to extract the time bits from your data, then reading them as POSIX dates and using difftime. for example, mytime - c(G2659310 2006-310-10-55-32.txt 10134 FALSE 666 2006-11-06 10:49:00 2006-11-13 10:56:41, G2659310 2006-310-11-31-43.txt 10136 FALSE 666 2006-11-06 11:25:00 2006-11-13 10:56:41, G2659310 2006-310-12-08-04.txt 10140 FALSE 666 2006-11-06 12:02:00 2006-11-13 10:56:41, G2659310 2006-310-12-43-17.txt 10148 FALSE 666 2006-11-06 12:38:00 2006-11-13 10:56:41, G2659310 2006-310-13-20-21.txt 10138 FALSE 666 2006-11-06 13:15:00 2006-11-13 10:56:41, G2659310 2006-310-13-56-28.txt 10080 FALSE 666 2006-11-06 13:51:00 2006-11-13 10:56:38) time1 - substring(mytime,49,67) time2 - substring(mytime,69,87) interval - difftime( as.POSIXct(time1, tz = AET10ADT), as.POSIXct(time2, tz = AET10ADT), units = hours) interval Time differences of -168.1281, -167.5281, -166.9114, -166.3114, - 165.6947, -165.0939 hours i'm not exactly sure what you're after, but here's a vector of time differences. in general the POSIX class holds the most detailed information about time -- note the specification of tz (time zone) -- and should be used when a great deal of precision is required. tc On 11/14/06, Warren [EMAIL PROTECTED] wrote: Dear R-helpers, I am trying to generalize my function for recording measurement times from file times mtime--my intervals are minutes to hours over the course of several days. I want to use hours as my units, and I have had trouble dealing with time units in a general way. I have a simple solution for the dealing with regular intervals, but I have not been able to handle irregular intervals. I tried using the zoo package, and had similar problems with the conversion of time units. Code and sample data is below-- for your info--after this, I am feeding the times and measurements to nls. Thanks in advance, -- Warren #Here is the failed code: myfilenames-row.names(myfileinfo) fileno-length(myfilenames) filetimes-numeric() for (i in 2:fileno){rel.read.time -myfileinfo$mtime[i]-myfileinfo$mtime[1] rel.read.time-( as.numeric(rel.read.time)) ##this next part is problematic ##i would love to say time.in.hours-as.hours (myfileinfo$mtime[i]-myfileinfo$mtime[1]) ifelse(rel.read.time =5, hour.read.time -(rel.read.time /60), hour.read.time-rel.read.time) filetimes-c(filetimes,rel.read.time)} #For regular intervals of readings, the code below generates measurement times from the first interval: myfilenames-row.names(myfileinfo) fileno-length(myfilenames) intervalue- myfileinfo$mtime[2] - myfileinfo$mtime[1] unitless.interval-(as.numeric(intervalue)) ifelse(unitless.interval =5, hour.interval-(unitless.interval/60), hour.interval-unitless.interval) hours-0 for (i in 1:(fileno-1)){hours-c(hours,(i*hour.interval))} myfileinfo - size isdir mode mtime ctime G2659310 2006-307-21-09-57.txt 10220 FALSE 666 2006-11-03 21:04:00 2006-11-13 10:56:39 G2659310 2006-307-21-45-55.txt 10230 FALSE 666 2006-11-03 21:40:00 2006-11-13 10:56:39 G2659310 2006-307-22-23-00.txt 10236 FALSE 666 2006-11-03 22:17:00 2006-11-13 10:56:39 G2659310 2006-307-23-00-33.txt 10236 FALSE 666 2006-11-03 22:54:00 2006-11-13 10:56:39 G2659310 2006-307-23-39-39.txt 10234 FALSE 666 2006-11-03 23:33:00 2006-11-13 10:56:39 G2659310 2006-308-00-17-25.txt 10234 FALSE 666 2006-11-04 00:11:00 2006-11-13 10:56:39 G2659310 2006-308-00-53-45.txt 10228 FALSE 666 2006-11-04 00:48:00 2006-11-13 10:56:39 G2659310 2006-308-01-30-03.txt 10208 FALSE 666 2006-11-04 01:25:00 2006-11-13 10:56:39 G2659310 2006-308-02-06-00.txt 10188 FALSE 666 2006-11-04 02:00:00 2006-11-13 10:56:39 G2659310 2006-308-02-41-57.txt 10168 FALSE 666 2006-11-04 02:36:00 2006-11-13 10:56:39 G2659310 2006-308-03-17-54.txt 10158 FALSE 666 2006-11-04 03:12:00 2006-11-13 10:56:39 G2659310 2006-308-03-53-51.txt 10148 FALSE 666 2006-11-04 03:48:00 2006-11-13 10:56:39 G2659310 2006-308-04-29-48.txt 10144 FALSE 666 2006-11-04 04:24:00 2006-11-13 10:56:39 G2659310 2006-308-05-05-44.txt 10132 FALSE 666 2006-11-04 05:00:00 2006-11-13 10:56:39 G2659310 2006-308-05-41-41.txt 10136 FALSE 666 2006-11-04 05:35:00 2006-11-13 10:56:39 G2659310 2006-308-06-17-39.txt 10128 FALSE 666 2006-11-04 06:11:00 2006-11-13 10:56:39 G2659310 2006-308-06-52-27.txt 10128 FALSE 666 2006-11-04 06:47:00 2006-11-13 10:56:39 G2659310 2006-308-07-28-25.txt 10130 FALSE 666 2006-11-04 07:23:00 2006-11-13 10:56:39 G2659310 2006
[R] creating and calling objects based on elements of another object...
Hi R community, I'd like to automatically create a number of matrices named for elements of another list or matrix. #I'm planning to deposit data into matrices named for plates in a platelist platelist- c(G2625462, G2625464, G2625466, G2625468, G2625470, G2625472, G2625474, G2625476, G2625478, G2625480, G2659264, G2659266, G2659268, G2659270, G2659272, G2659274, G2659276, G2659278, G2659280, G2661382, G2661384, G2661386, G2661388, G2661390, G2661392, G2661394, G2661396, G2661398, G2661400, G2661412, G2661414, G2661416, G2661418, G2661420, G2661562, G2661564, G2661568, G2661570, G2661576, G2661578, G2661580) platenumber-length(platelist) #failed attempt to create places to put data from each plate above platenumber-length(platelist) for (i in 1:platenumber){ as.name(platelist[i])-matrix() } #eventually I would like to use these matrices to read in the contents of multiple files, but using as.name hasn't worked her either. for (i in 1:fileno){ as.name(plateID[i])-cbind(as.name(plateID[i]),read.delim(myfilenames[i], header=FALSE)) } I have been trying multiple functions to force evaluation and treat these elements as objects, and I get errors like: could not find function as.name- Directly trying to create matrices doesn't work like this: for (i in 1:platenumber){ + platelist[i]-matrix() + } platelist [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA I am exploring the alternative of making an immense dataframe, and I'm trying to get through the R language definition documentation to build these functions--any expert advice would be tremendously helpful. Thanks for your time. Cheers, Warren Warren G. Lewis [EMAIL PROTECTED] __ 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] handling time units--hours, minutes, days--from file times
Dear R-helpers, I am trying to generalize my function for recording measurement times from file times mtime--my intervals are minutes to hours over the course of several days. I want to use hours as my units, and I have had trouble dealing with time units in a general way. I have a simple solution for the dealing with regular intervals, but I have not been able to handle irregular intervals. I tried using the zoo package, and had similar problems with the conversion of time units. Code and sample data is below-- for your info--after this, I am feeding the times and measurements to nls. Thanks in advance, -- Warren #Here is the failed code: myfilenames-row.names(myfileinfo) fileno-length(myfilenames) filetimes-numeric() for (i in 2:fileno){rel.read.time-myfileinfo$mtime[i]-myfileinfo$mtime[1] rel.read.time-(as.numeric(rel.read.time)) ##this next part is problematic ##i would love to say time.in.hours-as.hours (myfileinfo$mtime[i]-myfileinfo$mtime[1]) ifelse(rel.read.time =5, hour.read.time-(rel.read.time /60), hour.read.time-rel.read.time) filetimes-c(filetimes,rel.read.time)} #For regular intervals of readings, the code below generates measurement times from the first interval: myfilenames-row.names(myfileinfo) fileno-length(myfilenames) intervalue- myfileinfo$mtime[2] - myfileinfo$mtime[1] unitless.interval-(as.numeric(intervalue)) ifelse(unitless.interval=5, hour.interval-(unitless.interval/60), hour.interval-unitless.interval) hours-0 for (i in 1:(fileno-1)){hours-c(hours,(i*hour.interval))} myfileinfo - size isdir mode mtime ctime G2659310 2006-307-21-09-57.txt 10220 FALSE 666 2006-11-03 21:04:00 2006-11-13 10:56:39 G2659310 2006-307-21-45-55.txt 10230 FALSE 666 2006-11-03 21:40:00 2006-11-13 10:56:39 G2659310 2006-307-22-23-00.txt 10236 FALSE 666 2006-11-03 22:17:00 2006-11-13 10:56:39 G2659310 2006-307-23-00-33.txt 10236 FALSE 666 2006-11-03 22:54:00 2006-11-13 10:56:39 G2659310 2006-307-23-39-39.txt 10234 FALSE 666 2006-11-03 23:33:00 2006-11-13 10:56:39 G2659310 2006-308-00-17-25.txt 10234 FALSE 666 2006-11-04 00:11:00 2006-11-13 10:56:39 G2659310 2006-308-00-53-45.txt 10228 FALSE 666 2006-11-04 00:48:00 2006-11-13 10:56:39 G2659310 2006-308-01-30-03.txt 10208 FALSE 666 2006-11-04 01:25:00 2006-11-13 10:56:39 G2659310 2006-308-02-06-00.txt 10188 FALSE 666 2006-11-04 02:00:00 2006-11-13 10:56:39 G2659310 2006-308-02-41-57.txt 10168 FALSE 666 2006-11-04 02:36:00 2006-11-13 10:56:39 G2659310 2006-308-03-17-54.txt 10158 FALSE 666 2006-11-04 03:12:00 2006-11-13 10:56:39 G2659310 2006-308-03-53-51.txt 10148 FALSE 666 2006-11-04 03:48:00 2006-11-13 10:56:39 G2659310 2006-308-04-29-48.txt 10144 FALSE 666 2006-11-04 04:24:00 2006-11-13 10:56:39 G2659310 2006-308-05-05-44.txt 10132 FALSE 666 2006-11-04 05:00:00 2006-11-13 10:56:39 G2659310 2006-308-05-41-41.txt 10136 FALSE 666 2006-11-04 05:35:00 2006-11-13 10:56:39 G2659310 2006-308-06-17-39.txt 10128 FALSE 666 2006-11-04 06:11:00 2006-11-13 10:56:39 G2659310 2006-308-06-52-27.txt 10128 FALSE 666 2006-11-04 06:47:00 2006-11-13 10:56:39 G2659310 2006-308-07-28-25.txt 10130 FALSE 666 2006-11-04 07:23:00 2006-11-13 10:56:39 G2659310 2006-308-08-04-22.txt 10130 FALSE 666 2006-11-04 07:59:00 2006-11-13 10:56:39 G2659310 2006-308-08-40-20.txt 10134 FALSE 666 2006-11-04 08:35:00 2006-11-13 10:56:39 G2659310 2006-308-09-16-18.txt 10166 FALSE 666 2006-11-04 09:11:00 2006-11-13 10:56:39 G2659310 2006-308-09-52-15.txt 10180 FALSE 666 2006-11-04 09:46:00 2006-11-13 10:56:39 G2659310 2006-308-10-28-13.txt 10192 FALSE 666 2006-11-04 10:22:00 2006-11-13 10:56:39 G2659310 2006-308-11-04-10.txt 10210 FALSE 666 2006-11-04 10:58:00 2006-11-13 10:56:39 G2659310 2006-308-11-40-08.txt 10210 FALSE 666 2006-11-04 11:34:00 2006-11-13 10:56:39 G2659310 2006-308-12-16-06.txt 10222 FALSE 666 2006-11-04 12:10:00 2006-11-13 10:56:39 G2659310 2006-308-12-50-55.txt 10222 FALSE 666 2006-11-04 12:46:00 2006-11-13 10:56:39 G2659310 2006-308-13-26-54.txt 10224 FALSE 666 2006-11-04 13:21:00 2006-11-13 10:56:39 G2659310 2006-308-14-02-52.txt 10220 FALSE 666 2006-11-04 13:57:00 2006-11-13 10:56:39 G2659310 2006-308-14-38-51.txt 10224 FALSE 666 2006-11-04 14:33:00 2006-11-13 10:56:39 G2659310 2006-308-15-14-50.txt 10216 FALSE 666 2006-11-04 15:09:00 2006-11-13 10:56:39 G2659310 2006-308-15-50-47.txt 10202 FALSE 666 2006-11-04 15:45:00 2006-11-13 10:56:39 G2659310 2006-308-16-26-45.txt 10202 FALSE 666 2006-11-04 16:21:00 2006-11-13 10:56:39 G2659310 2006-308-17-02-43.txt 10190 FALSE 666 2006-11-04 16:57:00 2006-11-13 10:56:39 G2659310 2006-308-17-38-41.txt 10188 FALSE 666 2006-11-04 17:32:00 2006-11-13 10:56:39 G2659310 2006-308-18-14-40.txt 10174 FALSE 666 2006-11-04 18:08:00 2006-11-13 10:56:39 G2659310 2006-308-18-49-29.txt 10170 FALSE 666 2006-11-04 18:44:00 2006-11-13 10:56:39 G2659310 2006-308-19-25-28.txt 10158 FALSE 666 2006-11-04 19:20:00 2006-11-13 10:56:39 G2659310 2006
[R] during fitting of successive datasets, stall crashes iterations
Hi all, I am trying to do fitting of large sets of timeseries data, and error messages derail the process when I encounter a dataset that doesn't fit. I'd like to ignore those misfits and try another equation or move to the next dataset. Any ideas? (piece of code below) Thanks,--Warren ##The code looks something like this: attach(zf) x - hours n-length(zf[,2]) for (i in 2:n) {y - zf[,i] plot(y ~ x, xlab = Time (h), ylab = Lumi, pch = 15) # fitting algorithm looks like this: sine- nls (y ~ baseline + trend*x + amplitude*(sin(2*pi*(x+phase)/period)), start=list(baseline=4000, amplitude=4000, phase=0, period=24, trend=0), trace=TRUE) ... } -- Warren G. Lewis [EMAIL PROTECTED] [[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.
[R] recursive methods for concatenating sets of files
Hello, I would like to read sets of files within a folder, perhaps using recursive methods. Right now, I rename the files before import. It would be even better to do this without renaming files, without providing explicit filenames, perhaps by importing files based on chronology, and translating each filename into a header? Please excuse my ignorance, and help cure my clunky programming (below) with more elegant code. Thanks, Warren data0 -read.delim(t.txt, quote=, as.is=TRUE) data1 -read.delim(t (1).txt, quote=, as.is=TRUE) data2 -read.delim(t (2).txt, quote=, as.is=TRUE) data3 -read.delim(t (3).txt, quote=, as.is=TRUE) data4 -read.delim(t (4).txt, quote=, as.is=TRUE) data5 -read.delim(t (5).txt, quote=, as.is=TRUE) data6 -read.delim(t (6).txt, quote=, as.is=TRUE) data7 -read.delim(t (7).txt, quote=, as.is=TRUE) data8 -read.delim(t (8).txt, quote=, as.is=TRUE) data9 -read.delim(t (9).txt, quote=, as.is=TRUE) data10 -read.delim(t (10).txt, quote=, as.is=TRUE) data11 -read.delim(t (11).txt, quote=, as.is=TRUE) data12 -read.delim(t (12).txt, quote=, as.is=TRUE) data13 -read.delim(t (13).txt, quote=, as.is=TRUE) data14 -read.delim(t (14).txt, quote=, as.is=TRUE) data15 -read.delim(t (15).txt, quote=, as.is=TRUE) data16 -read.delim(t (16).txt, quote=, as.is=TRUE) data17 -read.delim(t (17).txt, quote=, as.is=TRUE) data18 -read.delim(t (18).txt, quote=, as.is=TRUE) data19 -read.delim(t (19).txt, quote=, as.is=TRUE) data20 -read.delim(t (20).txt, quote=, as.is=TRUE) data21 -read.delim(t (21).txt, quote=, as.is=TRUE) data22 -read.delim(t (22).txt, quote=, as.is=TRUE) data23 -read.delim(t (23).txt, quote=, as.is=TRUE) data24 -read.delim(t (24).txt, quote=, as.is=TRUE) data25 -read.delim(t (25).txt, quote=, as.is=TRUE) data26 -read.delim(t (26).txt, quote=, as.is=TRUE) data27 -read.delim(t (27).txt, quote=, as.is=TRUE) data28 -read.delim(t (28).txt, quote=, as.is=TRUE) data29 -read.delim(t (29).txt, quote=, as.is=TRUE) data30 -read.delim(t (30).txt, quote=, as.is=TRUE) data31 -read.delim(t (31).txt, quote=, as.is=TRUE) data32 -read.delim(t (32).txt, quote=, as.is=TRUE) data33 -read.delim(t (33).txt, quote=, as.is=TRUE) data34 -read.delim(t (34).txt, quote=, as.is=TRUE) data35 -read.delim(t (35).txt, quote=, as.is=TRUE) data36 -read.delim(t (36).txt, quote=, as.is=TRUE) data37 -read.delim(t (37).txt, quote=, as.is=TRUE) data38 -read.delim(t (38).txt, quote=, as.is=TRUE) data39 -read.delim(t (39).txt, quote=, as.is=TRUE) data40 -read.delim(t (40).txt, quote=, as.is=TRUE) data41 -read.delim(t (41).txt, quote=, as.is=TRUE) data42 -read.delim(t (42).txt, quote=, as.is=TRUE) data43 -read.delim(t (43).txt, quote=, as.is=TRUE) data44 -read.delim(t (44).txt, quote=, as.is=TRUE) data45 -read.delim(t (45).txt, quote=, as.is=TRUE) data46 -read.delim(t (46).txt, quote=, as.is=TRUE) data47 -read.delim(t (47).txt, quote=, as.is=TRUE) data48 -read.delim(t (48).txt, quote=, as.is=TRUE) data49 -read.delim(t (49).txt, quote=, as.is=TRUE) data50 -read.delim(t (50).txt, quote=, as.is=TRUE) data51 -read.delim(t (51).txt, quote=, as.is=TRUE) data52 -read.delim(t (52).txt, quote=, as.is=TRUE) data53 -read.delim(t (53).txt, quote=, as.is=TRUE) data54 -read.delim(t (54).txt, quote=, as.is=TRUE) data55 -read.delim(t (55).txt, quote=, as.is=TRUE) data56 -read.delim(t (56).txt, quote=, as.is=TRUE) data57 -read.delim(t (57).txt, quote=, as.is=TRUE) data58 -read.delim(t (58).txt, quote=, as.is=TRUE) data59 -read.delim(t (59).txt, quote=, as.is=TRUE) data60 -read.delim(t (60).txt, quote=, as.is=TRUE) data61 -read.delim(t (61).txt, quote=, as.is=TRUE) data62 -read.delim(t (62).txt, quote=, as.is=TRUE) data63 -read.delim(t (63).txt, quote=, as.is=TRUE) data64 -read.delim(t (64).txt, quote=, as.is=TRUE) data65 -read.delim(t (65).txt, quote=, as.is=TRUE) data66 -read.delim(t (66).txt, quote=, as.is=TRUE) data67 -read.delim(t (67).txt, quote=, as.is=TRUE) data68 -read.delim(t (68).txt, quote=, as.is=TRUE) data69 -read.delim(t (69).txt, quote=, as.is=TRUE) data70 -read.delim(t (70).txt, quote=, as.is=TRUE) data71 -read.delim(t (71).txt, quote=, as.is=TRUE) data72 -read.delim(t (72).txt, quote=, as.is=TRUE) data73 -read.delim(t (73).txt, quote=, as.is=TRUE) data74 -read.delim(t (74).txt, quote=, as.is=TRUE) data75 -read.delim(t (75).txt, quote=, as.is=TRUE) dataALL -cbind(data0,data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11,data12,data13,data14,data15,data16,data17,data18,data19,data20,data21,data22,data23,data24,data25,data26,data27,data28,data29,data20,data31,data32,data33,data34,data35,data36,data37,data38,data39,data40,data41,data42,data43,data44,data45,data46,data47,data48,data49,data50,data51,data52,data53,data54,data55,data56,data57,data58,data59,data60,data61,data62,data63,data64,data65,data66,data67,data68,data69,data70,data71,data72,data73,data74,data75) write.table(dataALL,0905p528.txt, quote=FALSE) -- [EMAIL PROTECTED
[R] R equivalent to Fortran, GAUSS, or Perl's goto
Does R have something equivalent to the goto in Perl? If so, can you please tell me what it is? I cannot find it in the Ref Manual or the Language Manual. Thanks. - Warren Warren Lamboy USDA-ARS Plant Genetic Resources Unit Geneva, NY, USA 14456 __ 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] R equivalent to Fortran, GAUSS, or Perl's goto
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Barry Rowlingson Sent: Wednesday, August 10, 2005 5:23 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] R equivalent to Fortran, GAUSS, or Perl's goto Warren Lamboy wrote: Does R have something equivalent to the goto in Perl? If so, can you please tell me what it is? I cannot find it in the Ref Manual or the Language Manual. What was true in 1968 is still true now: http://www.acm.org/classics/oct95/ Of course Perl has one, but then in Perl there's always more than one way to shoot yourself in the foot. Baz Does that mean the answer to my first question is No? Warren __ 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