[R-br] Ajuste não-linear usando tangente hiperbólica
Michelle Baú Graczyk
mbgraczyk em gmail.com
Quarta Agosto 20 14:48:56 BRT 2014
Boa tarde,
Estou começando com R agora e preciso ajustar um gráfico usando uma função
com tangente hiperbólica.
Então eu escrevi um programa para primeiro achar os parâmetros e depois
ajustar.
Só que dá um erro de gradiente singular e o R faz o ajuste com uma função
polinomial de graus 6.
O código e o erro seguem abaixo :
cra<-read.table("/Users/bau/Desktop/DIS2.txt", head=T)
head(cra)
str(cra)
dput(cra)
cra<- structure(list(min = 1:395, mu = c(40619.8, 39545.45, 19500.81,
14791.13, 9149.19, 9480.65,
12744.09, 11964.57, 11614.17, 11684.13,
10369.29, 13327.56, 9780.95,
12404.69, 10536.72, 12999.22, 12896.09,
14821.26, 11269.53, 9419.84,
8962.7, 12392.91, 10222.66, 10529.13,
10285.94, 11471.09, 14243.31,
9932.81, 9861.42, 9983.46, 10539.84,
9241.27, 7450, 11592.91, 12796.09,
10090.48, 10106.25, 9166.93,
8778.57, 7770.63, 10237.8,
10085.6, 8813.39, 9223.44, 9236, 11351.2,
12493.7, 12438.58, 9455.56,
8894.35, 10324.8, 9891.87, 10706.35,
9313.82, 10461.6, 10487.3,
10592.91, 9917.46, 9039.68, 8050,
10052.38, 11104.8, 12400.79, 9650,
10877.78, 13385.83, 10130.71,
9628.35, 9437.4, 8750, 11756,
12542.06, 9927.34, 13969.29, 9136.22,
11517.32, 9858.27, 10492.91, 8452,
10669.53, 10669.84, 9958.06,
10270.4, 9927.2, 9028.57, 12172.8,
10311.9, 8573.81, 6879.03,
10854.47, 8000, 8991.94, 11618.11,
10336, 15286.61, 11933.86,
10360.32, 10776.38, 7796.77,
9339.52, 9820.16, 10235.2, 9374.8,
9774.4, 9381.1, 10692.86,
10714.06, 9313.6, 12315.87, 9844.63,
11017.6, 9547.15, 10226.02,
11998.37, 10019.84, 8105.6, 8834.92,
14572, 8759.52, 8546.83, 10929.84,
11121.43, 11700, 7966.94,
9686.29, 9089.6, 10859.06,
8584.68, 8510.32, 7851.97, 9800, 9303.23,
10250, 9338.4, 9639.2, 9897.62,
8022.58, 9415.87, 7676.23, 8783.33,
9322.58, 8224.8, 7808.8, 10566.94,
8915.87, 9031.45, 8175, 8262.7,
8287.2, 7414.96, 11503.2, 9240,
9800.8, 8669.84, 10707.14, 8335.71,
9726.98, 8534.96, 10563.49,
8089.76, 9924.6, 8228.8, 7516.94,
10676.38, 8029.92, 9932.26,
7155.28, 9440.32, 10058.4, 8311.11,
8780.31, 9165.87, 8956.8, 8267.2,
8767.46, 9109.52, 9476.19,
8557.14, 5923.58, 8865.57,
7166.67, 8295.24, 9270.97, 8654.03,
7140, 7679.37, 12931.2, 8307.14,
7132, 6820.8, 8820.8, 6396.8,
6417.32, 8580.16, 9339.2, 7325.98,
7534.13, 9076.19, 7066.94,
7488.71, 8042.52, 7669.29,
9224.41, 8097.58, 8974.4, 8530.16,
8403.17, 8036.29, 9200, 6553.17,
7426.98, 7818.4, 7442.86, 7342.74,
10152.8, 7003.2, 8584.55, 8426.19,
7689.43, 10894.31, 9023.58,
7295.97, 7248.8, 8260, 6723.81,
10219.2, 7630.95, 7053.97, 7321.6,
8065.08, 7696.83, 7782.26, 8234.4,
8464.8, 15065.04, 7095.16,
7509.52, 10538.71, 10128.23,
7324.8, 8461.11, 7879.51, 8787.2,
9983.87, 7620.63, 9636.51, 8688,
8010.32, 7733.87, 6618.4, 8676.98,
6831.2, 9062.9, 6804.8, 7835.48,
9616.67, 8756.45, 8137.3, 8732.8,
7296.83, 8336.51, 8489.52, 7241.6,
9461.6, 8593.65, 8695.2, 9409.84,
8552.8, 8721.43, 7684.8, 8852,
9445.6, 12223.2, 11104.8, 11211.11,
8091.2, 10172.22, 8283.2,
10996.03, 9291.27, 13194.44, 8806.4,
11795.2, 12854.76, 10568.25,
11619.2, 9796.83, 11148.41, 10347.2,
12374.6, 11234.92, 10505.6,
12130.4, 9889.6, 9594.44, 11288.89,
10813.6, 11724.19, 10908.8,
10823.39, 12461.11, 17342.86, 11294.4,
13250, 13161.9, 11897.58, 10255.2,
10792, 12212.8, 10997.6, 12242.86,
9920.8, 8991.27, 9956.35,
11164.29, 12138.1, 11219.05, 12037.3,
12813.49, 9661.9, 13949.21,
10590.48, 14073.6, 11168.8, 12556.35,
12865.87, 13203.97, 13751.59,
11597.62, 14173.02, 16489.68, 11492.06,
13292.86, 10719.2, 11917.46,
12168.25, 13701.59, 12973.02, 12025.4,
11307.14, 16519.84, 10837.3,
12180.95, 12509.52, 10959.52, 14688.1,
14192.06, 14108.73, 13302.38,
12665.87, 16281.75, 13131.2, 14984.92,
14841.27, 13766.4, 15573.02,
14683.33, 15494.44, 13714.29, 14546.83,
18848.41, 15442.86, 18065.08,
16905.56, 18330.95, 19372.22, 19878.57,
18992.86, 16706.35, 15268.25,
20623.02, 19945.24, 20128.57, 18582.54,
19185.71, 23628.57, 22283.33,
20084.92, 21576.98, 27226.98, 26983.2,
24548.8, 26579.2, 26625.4,
28393.65, 33450, 31057.14, 29047.62,
35111.11, 45998.4, 99051.61,
178643.64, 104533.33, 70500, 104700
)), .Names = c("min", "mu"), class = "data.frame", row.names = c(NA,
-395L))
m0<- 0.5; a<-1; b<-3
plot(mu~min,cra)
curve(m0+(tanh(a*min+b*(min^2)))^3, add=TRUE)
n0<-nls(mu~m0+(tanh(a*min))^b,data=cra,start=list(m0=m0,a=a,b=b))
summary(n0)
with(cra,plot(min,mu,xlab="minutos",ylab="média"))
with(cra,points(min,fitted(n0),type="b",pch="+",col="red"))
legend(200,100000,c("observado","ajustado)"),pch=c(1,3),col=c(1,2))
O erro:
>
n0<-nls(mu~m0+(tanh(a*min+b*(min^2)))^3,data=cra,start=list(m0=0.5,a=1,b=0.9))
Erro em nls(mu ~ m0 + (tanh(a * min + b * (min^2)))^3, data = cra, start =
list(m0 = 0.5, :
gradiente singular
> summary(n0)
Formula: mu ~ m0 + a * (min^3) + b * (min^6)
Parameters:
Estimate Std. Error t value Pr(>|t|)
m0 1.226e+04 7.472e+02 16.411 <2e-16 ***
a -7.917e-04 9.122e-05 -8.679 <2e-16 ***
b 2.294e-11 1.758e-12 13.048 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 9538 on 392 degrees of freedom
Number of iterations to convergence: 2
Achieved convergence tolerance: 2.397e-07
Alguém saberia como eu posso resolver este problemas?
Muito obrigada,
Michelle Bau Graczyk
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20140820/f1bf3493/attachment.html>
Mais detalhes sobre a lista de discussão R-br