我正在尝试使用R中的minpack.lm包。特别是NLS.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个参数。
谢谢, 汤姆
答案 0 :(得分:3)
阅读?nls.lm
您需要传递函数,而不是调用函数
out <- nls.lm(par = guess, fn = GWLF, dischargeInput, weatherInput)
请注意额外的参数(我假设是数据)在...
使用您希望它们在GWLF
内的任何参数名称来命名这些参数会更安全。