因此,我有一個系統的ode和一些數據,我正在使用R包deSolve和FME來匹配ode系統的參數到數據。當我將完整的參數設置爲數據時,我得到一個奇異的矩陣結果。所以我回過頭來看看所有FME軟件包文檔中建議的共線性索引截止值爲20的參數的共線性,然後我選擇了幾個參數子集的模型進行擬合。後來,當我跑MODFIT我得到這個錯誤:嘗試在R包FME中使用collin函數來識別參數,然後使用modFit來匹配它們
錯誤約(XMOD,yMod,XOUT = XDAT): 至少需要兩個非NA值進行插值
誰能賜教,以修復爲了這。其他一切工作正常。所以這不是一個編碼問題。
這裏是一個最小的工作示例(除去R = 2 MODFIT創建,我可以在最少的工作示例修復,但不是我的實際問題,所以我懷疑一個最小的工作示例幫助這裏的錯誤):
`## =======================================================================
## Now suppose we do not know K and r and they are to be fitted...
## The "observations" are the analytical solution
## =======================================================================
# You need these packages
library('deSolve')
library('FME')
## logistic growth model
TT <- seq(1, 100, 2.5)
N0 <- 0.1
r <- 0.5
K <- 100
## analytical solution
Ana <- cbind(time = TT, N = K/(1 + (K/N0 - 1) * exp(-r*TT)))
time <- 0:100
parms <- c(r = r, K = K)
x <- c(N = N0)
logist <- function(t, x, parms) {
with(as.list(parms), {
dx <- r * x[1] * (1 - x[1]/K)
list(dx)
})
}
## Run the model with initial guess: K = 10, r = 2
parms["K"] <- 10
parms["r"] <- 2
init <- ode(x, time, logist, parms)
## FITTING algorithm uses modFit
## First define the objective function (model cost) to be minimised
## more general: using modFit
Cost <- function(P) {
parms["K"] <- P[1]
parms["r"] <- P[2]
out <- ode(x, time, logist, parms)
return(modCost(out, Ana))
}
(Fit<-modFit(p = c(K = 10,r=2), f = Cost))
summary(Fit)`
歡迎來到SO。請閱讀:http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – pcantalupo
好吧,已經發布了一個工作示例,但不確定它會解決問題。 –