2013-04-12 111 views
0

我想在R.使用minpack.lm包,專門的NLS.LM功能。我正在翻閱手冊和幫助文件,但是設置它的要求稍微超出了我目前的能力。任何指導非常感謝。下面是我的代碼和我得到的錯誤陳述。問題有關使用NLS.LM在minpack.lm包

R代碼裏面:

# Thomas P. Taggart 
# ERE445/645 
# Spring 2013 - Calibration Presentation 

# Lumped parameter rainfall-runoff model for the Susquehanna River at Conklin, NY. 
# Outlined in Haith's (1987) GWLF model. The model uses the SCS curve 
# number runoff technique to determine runoff, with snowpack, unsaturated zone, and 
# saturated zone mass balances. Evapotranspiration is to be determined using Hamon’s 
# method with average monthly values for daylight hours. 
# In this model we assume the following constants, which are determined through calibration: 
# Baseflow Recession Coefficient, Kb 
# Field capacity, FCAP 
# Curve number for average moisture conditions, CN2 
# Initial antecedent moisture conditions, iAMC 
# Initial snow accumulation, iSNt 
# Initial saturated zone storage, iSATt 
# No deep groundwater seepage 

# including needed functions 
source("Functions.R") 
source("distributionFunctions.R") 
source("GWLF_Model.R") 

require(ggplot2) 
require(reshape) 
library(minpack.lm) 
library(scales) 


############################################################################################### 
# USGS Discharge data for Conklin, NY - Gage on the Susquehanna 

# Reading in the input file 
dischargeInput <- read.csv("USGS_DailyDischarge_ConklinNY_01503000_A.csv", header=TRUE) 


############################################################################################### 
# Weather Data 

# Read in input file 
weatherInput = read.csv("Conklin_NY_WeatherData_Edit.csv") 


############################################################################################### 
# Setting up the model inputs - inital Run 

# Baseflow Recession, Kb 
Kb <- 0.90 

# Initial unsaturated storage is at field capacity, FCAP (cm) 
FCAP <- 10 

# Curve number for average moisture conditions, CN 
CN <- 65.7 

# Initial antecedent moisture conditions, AMC 
AMC <- 1.5 

# Initial saturated zone storage, SATt 
iSATt <- 0.45 

# Snowmelt constant, K 
K <- 0.45 

parameters <- c(Kb, FCAP,CN, AMC, iSATt, K) 

# Calling the Model - 1st time to see the initial outputs 
# GWLF(parameters, dischargeInput, weatherInput) 


############################################################################################### 
# Calibrating the model 

guess <- c("Kb"=0.1, "FCAP"=1,"CN"=50, "AMC"=0, "iSATt"=0, "K"=0.5) 

out <- nls.lm(par = guess, fn = GWLF(parameters, dischargeInput, weatherInput)) 

以下是錯誤消息:

Error in function (par) : could not find function "fn" 

如何需要設置標準?或者我在nls.lm中調用的函數中的第一個參數? 該GWLF功能被傳遞被用作在功能常量6個參數。這些是我希望校準的6個參數。

感謝, 湯姆

回答

3

從閱讀?nls.lm

你需要傳遞的功能,而不是一個函數調用

out <- nls.lm(par = guess, fn = GWLF, dischargeInput, weatherInput) 

注意額外的參數(我假設是數據)的範圍內...

通過這將是更安全的名稱中使用whate這些參數你希望這些版本參數名是內GWLF

+0

MNEL,哇!我只是在幾分鐘前纔開始工作,而這正是我如何工作。究竟。我知道面臨的問題是,爲什麼我的迭代在第二次後停止(甚至認爲圖的數量表明它應該高於兩次迭代),以及爲什麼最終的par輸出與初始值沒有任何不同猜測值。 – traggatmot

+0

@traggatmot,那將是難以協助,除非你能提供一個可重複的例子 – mnel