2012-09-17 56 views
1

我喜歡以適應非線性方程(g和h是所述參數):非線性方程ř

Q = G *(H **年齡)/(1 + G *(H **年齡) );
限制Q = 0.05時年齡= 50: 即克*(H * 50)/(1 +克(H ** 50)= 0.05
這意味着當年齡= 50 預測值q等於在數據的q值。

感謝您的幫助。

回答

2

nls()看看和/或包裝BB。 但對於真正的樂趣:-),花一點時間與Eureqa ,http://creativemachines.cornell.edu/eureqa。你會得到比你想象的更多的解決方案!

+0

謝謝你與Eureqa,Carl的一個有趣的建議。你能證明nls/BB的力量嗎(甚至可能是一個模擬的例子)? –

+0

我認爲@羅蘭的回答爲我做了這份工作。但是你是對的:我應該包含虛擬代碼以及軟件包引用。 –

2
#define function 
qfun <- function(age,h){ 
    #the constraint can be added using algebra 
    g <- 0.05/0.95/h^50 
    g * (h^age)/(1 + g * (h^age)) 
}  

#create data 
age <- 1:75 

h <- 0.75 

q <- qfun(age,h) 
plot(q~age) 
#add noise 
q <- q+rnorm(length(q),sd=0.02) 
plot(q~age) 

#fit 
fit <- nls(q~qfun(age,h),start=list(h=1)) 
summary(fit) 
Formula: q ~ qfun(age, h) 

#Parameters: 
# Estimate Std. Error t value Pr(>|t|)  
#h 0.749644 0.001678 446.7 <2e-16 *** 
#--- 
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
# 
#Residual standard error: 0.01865 on 74 degrees of freedom 
# 
#Number of iterations to convergence: 5 
#Achieved convergence tolerance: 1.735e-06 
ttt<- function(x) qfun(x,coef(fit)[1]) 
curve(ttt,from=1,to=75,add=TRUE) 
+0

「g <-0.05/0.95/h^50」是指「g *(h * 50)/(1 + g(h ** 50)= 0.05」 – user1582755