In [1]:
using RDatasets, NLreg, Gadfly

In [2]:
cw2 = DataFrame(
 x=[0.5,1,1.75,3.75,5.75,0.875,2.25,3.25,5.25,0.75,1.75,
    2.75,4.75,0.625,1.25,2.25,4.25,0.5,3,0.75,3,1.5,6,
    3,6,1.5,3,0.5,2,4,0.75,2,5,0.75,2.25,3.75,5.75,
	3,0.75,2.5,4,0.75,2.5,4,0.75,2.5,4,0.5,6,3,0.5,
	2.75,0.5,1.75],
 y=[92.9,57.1,31.05,11.5875,8.025,63.6,21.4,14.25,8.475,
    63.8,26.8,16.4625,7.125,67.3,41,21.15,8.175,81.5,13.12,
	59.9,14.62,32.9,5.44,12.56,5.44,32,13.95,75.8,20,10.42,
	59.5,21.67,8.55,62,20.2,7.76,3.75,11.81,54.7,23.7,11.55,
	61.3,17.7,8.74,59.2,16.3,8.62,81,4.87,14.62,81.7,17.17,
    81.3,28.9]);
plot(cw2, x = "x", y = "y")


Out[2]:
x -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -6.0 -5.8 -5.6 -5.4 -5.2 -5.0 -4.8 -4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0 8.2 8.4 8.6 8.8 9.0 9.2 9.4 9.6 9.8 10.0 10.2 10.4 10.6 10.8 11.0 11.2 11.4 11.6 11.8 12.0 -10 0 10 20 -6.0 -5.5 -5.0 -4.5 -4.0 -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 -100 0 100 200 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 y

In [3]:
fm2 = fit(Chwirut(y ~ x,cw2))


Out[3]:
Nonlinear least squares fit to 54 observations

     Estimate Std.Error t value Pr(>|t|)
R0    193.599   24.9701 7.75323    <1e-9
rc   0.166576 0.0383033 4.34888    <1e-4
m     2.35223  0.593953 3.96029   0.0002

Residual sum of squares at estimates: 513.048
Residual standard error = 3.17171 on 51 degrees of freedom

In [4]:
pur = dataset("datasets","Puromycin");
purtrt = sub(pur, pur[:State] .== "treated");
plot(purtrt,x="Conc",y="Rate")


Out[4]:
Conc -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 -1.50 -1.45 -1.40 -1.35 -1.30 -1.25 -1.20 -1.15 -1.10 -1.05 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 2.70 2.75 2.80 2.85 2.90 2.95 3.00 -2 0 2 4 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 -250 0 250 500 -260 -240 -220 -200 -180 -160 -140 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 Rate

In [5]:
pm1 = fit(MicMen(Rate ~ Conc,purtrt),true)


Iteration:  1, rss = 1679.58, cvg = 0.257787 at [201.837,0.0484065]
   Incr: [0.012547]
  f = 1.0, rss = 1211.92
Iteration:  2, rss = 1211.92, cvg = 0.0122645 at [210.623,0.0609536]
   Incr: [0.00280048]
  f = 1.0, rss = 1195.66
Iteration:  3, rss = 1195.66, cvg = 0.000161307 at [212.448,0.063754]
   Incr: [0.000331041]
  f = 1.0, rss = 1195.45
Iteration:  4, rss = 1195.45, cvg = 1.56158e-6 at [212.661,0.0640851]
   Incr: [3.27084e-5]
  f = 1.0, rss = 1195.45
Iteration:  5, rss = 1195.45, cvg = 1.4557e-8 at [212.681,0.0641178]
   Incr: [3.15934e-6]
  f = 1.0, rss = 1195.45
Iteration:  6, rss = 1195.45, cvg = 1.35192e-10 at [212.684,0.0641209]
   Incr: [3.04477e-7]
  f = 1.0, rss = 1195.45

Out[5]:
Nonlinear least squares fit to 12 observations

      Estimate  Std.Error t value Pr(>|t|)
Vm     212.684    6.94715 30.6145   <1e-10
K    0.0641212 0.00828095 7.74323    <1e-4

Residual sum of squares at estimates: 1195.45
Residual standard error = 10.9337 on 10 degrees of freedom

In [6]:
pm2 = fit(MicMen(Rate ~ Conc,sub(pur,pur[:State] .== "untreated")))


Out[6]:
Nonlinear least squares fit to 11 observations

      Estimate  Std.Error t value Pr(>|t|)
Vm      160.28    6.48024 24.7336    <1e-8
K    0.0477081 0.00778187 6.13068   0.0002

Residual sum of squares at estimates: 859.604
Residual standard error = 9.773 on 9 degrees of freedom

In [7]:
@time fit(MicMen(Rate ~ Conc,sub(pur,pur[:State] .== "untreated")));


elapsed time: 0.005277077 seconds (186648 bytes allocated)