I have a table like the following. I want to fit Cm to Vm like this: Cm ~ Cl+Q1*b1*38.67*exp(-b1*(Vm-Vp1)*0.03867)/(1+exp(-b1*(Vm-Vp1)*0.03867))^2+Q2*b2*38.67*exp(-b2*(Vm-Vp2)*0.03867)/(1+exp(-b2*(Vm-Vp2)*0.03867))^2 I use nls, with start=list(Q1=2e-3, b1=1, Vp1=-25, Q2=3e-3, b2=1, Vp2=200). But I always get 'singlular gradient' error like this. But in SigmaPlot I can get the result. How can I get with R. Thanks! The table: "Vm" "Cm" "Ih" -147.715 8.15 -0.107 -146.944 8.081 -0.106 -146.173 8.089 -0.106 -145.409 8.114 -0.108 -144.638 8.105 -0.107 -143.873 8.085 -0.105 -143.102 8.151 -0.102 -142.338 8.084 -0.1 -141.567 8.079 -0.101 -140.796 8.077 -0.101 -140.032 8.077 -0.102 -139.261 8.126 -0.101 -138.497 8.153 -0.099 -137.726 8.129 -0.097 -136.962 8.073 -0.096 -136.191 8.088 -0.097 -135.426 8.119 -0.098 -134.655 8.121 -0.098 -133.885 8.062 -0.096 -133.12 8.135 -0.093 -132.349 8.089 -0.091 -131.585 8.065 -0.091 -130.814 8.064 -0.092 -130.05 8.071 -0.094 -129.279 8.139 -0.092 -128.515 8.15 -0.09 -127.744 8.119 -0.087 -126.973 8.074 -0.086 -126.208 8.083 -0.087 -125.438 8.084 -0.088 -124.673 8.102 -0.089 -123.902 8.083 -0.087 -123.138 8.132 -0.084 -122.367 8.108 -0.082 -121.596 8.072 -0.083 -120.832 8.07 -0.083 -120.061 8.083 -0.085 -119.297 8.134 -0.084 -118.532 8.14 -0.081 -117.762 8.119 -0.078 -116.997 8.078 -0.077 -116.226 8.102 -0.079 -115.455 8.112 -0.08 -114.691 8.104 -0.08 -113.92 8.093 -0.078 -113.156 8.126 -0.075 -112.385 8.109 -0.073 -111.621 8.066 -0.073 -110.85 8.054 -0.074 -110.085 8.077 -0.076 -109.315 8.134 -0.075 -108.544 8.133 -0.073 -107.779 8.131 -0.069 -107.008 8.093 -0.068 -106.244 8.113 -0.069 -105.473 8.094 -0.071 -104.709 8.106 -0.071 -103.938 8.1 -0.069 -103.174 8.135 -0.066 -102.403 8.115 -0.064 -101.632 8.061 -0.065 -100.868 8.05 -0.066 -100.097 8.091 -0.067 -99.332 8.122 -0.066 -98.561 8.137 -0.064 -97.797 8.123 -0.061 -97.026 8.098 -0.061 -96.255 8.117 -0.061 -95.491 8.108 -0.063 -94.72 8.107 -0.063 -93.956 8.108 -0.062 -93.185 8.144 -0.059 -92.421 8.115 -0.057 -91.65 8.078 -0.057 -90.885 8.053 -0.058 -90.114 8.093 -0.06 -89.344 8.134 -0.059 -88.579 8.147 -0.057 -87.815 8.122 -0.054 -87.044 8.08 -0.053 -86.28 8.128 -0.054 -85.509 8.094 -0.055 -84.745 8.114 -0.056 -83.974 8.119 -0.054 -83.203 8.135 -0.051 -82.438 8.122 -0.049 -81.667 8.062 -0.049 -80.903 8.072 -0.05 -80.132 8.094 -0.052 -79.368 8.142 -0.051 -78.597 8.131 -0.049 -77.826 8.122 -0.046 -77.062 8.097 -0.045 -76.291 8.138 -0.046 -75.527 8.094 -0.048 -74.756 8.124 -0.048 -73.991 8.116 -0.046 -73.221 8.137 -0.044 -72.456 8.118 -0.042 -71.685 8.082 -0.042 -70.914 8.051 -0.043 -70.15 8.089 -0.044 -69.379 8.143 -0.044 -68.615 8.14 -0.042 -67.844 8.113 -0.039 -67.08 8.099 -0.038 -66.309 8.139 -0.039 -65.544 8.084 -0.041 -64.774 8.119 -0.041 -64.003 8.144 -0.039 -63.238 8.142 -0.037 -62.467 8.142 -0.035 -61.703 8.076 -0.035 -60.932 8.069 -0.036 -60.168 8.093 -0.037 -59.397 8.133 -0.037 -58.626 8.131 -0.035 -57.862 8.107 -0.032 -57.098 8.106 -0.031 -56.327 8.146 -0.032 -55.562 8.091 -0.033 -54.791 8.12 -0.034 -54.027 8.141 -0.032 -53.256 8.138 -0.03 -52.485 8.143 -0.028 -51.721 8.071 -0.028 -50.95 8.058 -0.029 -50.186 8.097 -0.03 -49.415 8.146 -0.03 -48.651 8.128 -0.028 -47.88 8.125 -0.025 -47.115 8.116 -0.024 -46.344 8.15 -0.025 -45.573 8.092 -0.026 -44.809 8.142 -0.027 -44.038 8.159 -0.026 -43.274 8.164 -0.023 -42.503 8.161 -0.021 -41.739 8.078 -0.021 -40.968 8.079 -0.022 -40.204 8.105 -0.024 -39.433 8.157 -0.023 -38.662 8.15 -0.021 -37.897 8.131 -0.018 -37.127 8.122 -0.017 -36.362 8.149 -0.018 -35.591 8.092 -0.02 -34.827 8.138 -0.02 -34.056 8.16 -0.019 -33.285 8.152 -0.017 -32.521 8.164 -0.014 -31.75 8.092 -0.014 -30.986 8.074 -0.015 -30.215 8.094 -0.017 -29.45 8.148 -0.016 -28.68 8.151 -0.014 -27.915 8.121 -0.012 -27.144 8.125 -0.01 -26.38 8.162 -0.011 -25.609 8.094 -0.012 -24.845 8.132 -0.013 -24.074 8.17 -0.011 -23.31 8.158 -0.01 -22.539 8.153 -0.007 -21.774 8.081 -0.007 -21.004 8.09 -0.008 -20.233 8.103 -0.01 -19.468 8.151 -0.009 -18.697 8.124 -0.007 -17.933 8.132 -0.005 -17.162 8.122 -0.003 -16.398 8.149 -0.004 -15.627 8.081 -0.005 -14.863 8.13 -0.006 -14.092 8.157 -0.004 -13.321 8.175 -0.003 -12.557 8.157 0 -11.786 8.078 0 -11.021 8.085 -0.001 -10.25 8.106 -0.002 -9.486 8.145 -0.002 -8.715 8.13 0 -7.944 8.136 0.003 -7.18 8.108 0.005 -6.409 8.132 0.004 -5.645 8.099 0.002 -4.874 8.134 0.002 -4.11 8.158 0.003 -3.339 8.165 0.005 -2.574 8.162 0.008 -1.803 8.082 0.008 -1.033 8.087 0.007 -0.268 8.096 0.005 0.503 8.137 0.006 1.267 8.121 0.008 2.038 8.122 0.01 2.802 8.12 0.012 3.566 8.124 0.011 4.337 8.091 0.01 5.108 8.125 0.009 5.873 8.147 0.011 6.643 8.172 0.013 7.408 8.146 0.015 8.179 8.081 0.016 8.943 8.086 0.015 9.714 8.114 0.013 10.485 8.131 0.014 11.249 8.103 0.016 12.02 8.127 0.018 12.784 8.108 0.02 13.555 8.107 0.019 14.32 8.087 0.018 15.09 8.106 0.017 15.855 8.142 0.019 16.626 8.164 0.021 17.397 8.138 0.024 18.161 8.068 0.024 18.932 8.075 0.023 19.696 8.088 0.022 20.467 8.126 0.022 21.231 8.103 0.025 22.002 8.127 0.027 22.766 8.091 0.029 23.537 8.1 0.028 24.308 8.082 0.027 25.073 8.106 0.026 25.844 8.159 0.028 26.608 8.166 0.03 27.379 8.138 0.033 28.143 8.07 0.033 28.914 8.092 0.033 29.685 8.101 0.031 30.449 8.104 0.031 31.22 8.08 0.033 31.984 8.125 0.036 32.755 8.101 0.038 33.52 8.099 0.038 34.284 8.085 0.037 35.055 8.095 0.036 35.826 8.155 0.037 36.59 8.169 0.039 37.361 8.128 0.042 38.125 8.078 0.043 38.896 8.085 0.042 39.66 8.102 0.041 40.431 8.115 0.041 41.196 8.092 0.043 41.967 8.139 0.046 42.737 8.098 0.048 43.502 8.084 0.048 44.273 8.09 0.047 45.037 8.095 0.046 45.808 8.147 0.048 46.572 8.169 0.05 47.343 8.132 0.053 48.107 8.084 0.054 48.878 8.087 0.053 49.649 8.11 0.052 50.414 8.116 0.052 51.184 8.085 0.054 51.949 8.152 0.057 52.72 8.1 0.059 53.484 8.081 0.059 54.255 8.09 0.058 55.026 8.085 0.057 55.79 8.152 0.059 56.561 8.173 0.061 57.325 8.128 0.064 58.096 8.08 0.065 58.86 8.1 0.064 59.631 8.116 0.063 60.396 8.108 0.063 61.167 8.093 0.065 61.938 8.135 0.068 62.702 8.092 0.07 63.473 8.078 0.07 64.237 8.09 0.07 65.001 8.079 0.068 65.772 8.154 0.07 66.537 8.18 0.072 67.307 8.135 0.075 68.078 8.067 0.076 68.843 8.093 0.076 69.614 8.102 0.075 70.378 8.116 0.074 71.149 8.077 0.077 71.913 8.133 0.08 72.684 8.103 0.082 73.455 8.073 0.082 74.219 8.078 0.082 74.99 8.086 0.081 75.754 8.134 0.082 76.525 8.163 0.084 77.29 8.125 0.088 78.061 8.081 0.089 78.825 8.089 0.088 79.596 8.115 0.087 80.367 8.11 0.087 81.131 8.087 0.089 81.902 8.158 0.093 82.666 8.106 0.095 83.437 8.069 0.095 84.201 8.074 0.094 84.972 8.088 0.093 85.737 8.139 0.094 86.507 8.161 0.097 87.278 8.127 0.1 88.043 8.087 0.101 88.814 8.097 0.1 89.578 8.11 0.1 90.349 8.131 0.1 91.113 8.092 0.102 91.884 8.141 0.105 92.648 8.121 0.108 93.419 8.068 0.108 94.19 8.074 0.107 94.954 8.071 0.106 95.719 8.134 0.108 96.49 8.131 0.11 97.254 8.127 0.113 98.025 8.092 0.115 98.796 8.111 0.114 99.56 8.108 0.113 100.331 8.111 0.113 101.095 8.098 0.115 101.866 8.148 0.118 102.631 8.104 0.121 103.401 8.074 0.121 104.166 8.074 0.121 104.937 8.079 0.12 105.708 8.131 0.121 106.472 8.16 0.123 107.243 8.124 0.127 108.007 8.093 0.128 108.778 8.105 0.127 109.542 8.103 0.127 110.313 8.131 0.127 111.077 8.096 0.129 111.848 8.138 0.132 112.619 8.123 0.134 113.384 8.077 0.134 114.155 8.056 0.134 114.919 8.093 0.133 115.69 8.131 0.134 116.454 8.13 0.137 117.225 8.128 0.141 117.996 8.098 0.142 118.76 8.119 0.141 119.531 8.086 0.141 120.295 8.124 0.14 121.066 8.117 0.143 121.831 8.143 0.146 122.602 8.118 0.148 123.366 8.086 0.149 124.137 8.045 0.149 124.908 8.08 0.148 125.672 8.131 0.149 126.436 8.144 0.151 127.207 8.122 0.155 127.971 8.102 0.156 128.742 8.13 0.155 129.507 8.094 0.155 130.278 8.121 0.154 131.048 8.125 0.157 131.813 8.125 0.16 132.584 8.118 0.162 133.348 8.068 0.163 134.119 8.051 0.162 134.883 8.073 0.162 135.654 8.129 0.163 136.418 8.141 0.165 137.189 8.126 0.169 137.96 8.088 0.17 138.725 8.123 0.17 139.495 8.094 0.169 140.26 8.125 0.169 141.031 8.138 0.171 141.795 8.135 0.174 142.566 8.12 0.177 143.337 8.06 0.177 144.101 8.063 0.177 144.872 8.092 0.176 145.636 8.122 0.177 146.407 8.13 0.18 147.171 8.121 0.183 147.942 8.122 0.185 148.707 8.13 0.184 -- Ruqiang Liang, Ph. D. Department of Surgery-Otolaryngology, University of Kentucky Chandler Medical Center, 800 Rose Street, Lexington, KY 40536 Tel: (859)-323-1110
Ruqiang Liang <ruqiang.liang <at> gmail.com> writes:> > I have a table like the following. I want to fit Cm to Vm like this: > Cm ~Cl+Q1*b1*38.67*exp(-b1*(Vm-Vp1)*0.03867)/(1+exp(-b1*(Vm-Vp1)*0.03867))^2+Q2*b2*38.67*exp(-b2*(Vm-Vp2)*0.03867)/(1+exp(-b2*(Vm-Vp2)*0.03867))^2> > I use nls, with start=list(Q1=2e-3, b1=1, Vp1=-25, Q2=3e-3, b2=1, > Vp2=200). But I always get 'singular gradient' error like this. But > in SigmaPlot I can get the result. How can I get with R.I remember a similar case in gastric emptying fitting where my colleague tried to show me that SigmaPlot is superior to R/nls. When he looked at the standard deviations of the coefficients, giving estimated gastric empty times of 40 minutes plus minus 800 minutes, I was reminded of Douglas Bates' philosophy: better nothing than wrong. (Even if I would love to have estimated p-values back in lmer fits.) This said, there are two solutions: first, simplify your expression to see what you are doing. The first part of the expression can be written as R1*exp(-c1*(Vm-Vp1))/(1+exp(-c1*(Vm-Vp1))^2 where you are free to compute Q1 and b1 later. You will also note that your fit cannot have a unique solution because of the symmetry in the second term. As a next step, try to fit R1*exp(-exp(d1)*(Vm-Vp1))/(1+exp(-exp(d1)*(Vm-Vp1))^2 This gives a working solution in most cases, effectively forcing a positive c1=exp(d1). However, even that may fail in degenerate cases. If it is not a single fit, but from a planned pharmacology related experiment, you should try to fit the whole experiment with all repeats instead of single curves. This often gives excellent results even when some fits are disastrous. Check package nlme, the book by Pinheiro/Bates, and some related examples on http://www.menne-biomed.de/gastempt Dieter