2012-04-19 94 views
2

我正在嘗試使用nls來將高斯峯適用於R中的密度圖。當我用下面的公式:R:在使用nls解析時出錯

fit <- nls(den.PA$y~coeffs2 * exp(- ((den.PA$x-coeffs3)/coeffs4)**2), 
      start=list(coeffs2=1.12e-2, coeffs3=1075, coeffs4=2)) 

我得到以下錯誤:

Error in parse(text = x) : <text>:2:0: unexpected end of input 
1: ~ 
^

任何人都可以指出我哪裏出了問題?

回答

3

嘗試

fit <- nls(y~coeffs2 * exp(- ((x-coeffs3)/coeffs4)**2),data=den.PA, 
     start=list(coeffs2=1.12e-2, coeffs3=1075, coeffs4=2)) 
+0

這給了這個錯誤:不能強迫類的‘密度’「成data.frame – Harpal 2012-04-19 13:02:05

+1

谷歌上搜索我的工作了錯誤後,我不得不把在x和y的值的自己的矩陣。但你的回答讓我走上正確的道路:) – Harpal 2012-04-19 13:27:44

+0

在這種情況下工作,但通常是將值放入數據框。這將允許一般情況下的因素,例如lm或lme。 – 2012-04-20 06:15:46