0

我正在尝试使用 R 中的 minpack.lm 包。特别是 NLS.LM 函数。我正在翻阅手册和帮助文件,但设置它的要求有点超出我目前的能力。非常感谢任何指导。这是我的代码,以及我得到的错误声明,如下所示。

代码:

# 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 个参数。

谢谢,汤姆

4

1 回答 1

3

从阅读?nls.lm

您需要传递函数,而不是调用函数

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

注意额外的参数(我假设是数据)在内部传递...

使用您希望它们包含的任何参数名称来命名这些参数会更安全GWLF

于 2013-04-12T05:52:54.560 回答