sollano / forestmangr

R package for forest mensuration and management
Other
16 stars 8 forks source link

Missing Coefficients Using nls_table() with start = "tablename" #1

Open m1mels73 opened 4 years ago

m1mels73 commented 4 years ago

I am using the nls_table() function with two data frames. The first data frame contains my explanatory variable, response variable, and group by variable; the second data frame contains my group by variable and starting values (by group) for my model with 3 coefficients. When I run the function with the ' output = "table" ' option I get a table with only the group by value. If i comment out the 'start = "tablename" ' and set "start =" a vector with 3 fixed values, the output table contains my group by variable plus the 3 coefficients (b0, b1, b2). Can you provide more guidance?

sollano commented 4 years ago

Hello. When you say " If i comment out the 'start = "tablename" ' ", are you actually using your tablename object inside quotation marks? It should be the bare object name. Also, the argument name is "mod_start," like so:

nls_table(exfm14, dh ~ b0 (1 - exp( -b1 age ) )^b2, mod_start = tablename , .groups = "strata" )

Can you check that for me, please? If those things are correct, it may be possible that the function is not converging, i.e., you could try different starting values, and see if anything changes.

Anyhow, I should make an update where the function issues a warning when converging fails.

If you provide an example, I may be able to help out more.

m1mels73 commented 4 years ago

Before I get started, thank you and your team for publishing this library and thank you for your prompt response. I have pasted the command syntax i am using along with sample data structure. The comments I referred to were just options for me to enable/disable certain lines as I tried to work through my issue.

CumMatch99 <- nls_table( X10WellTest ,GAS ~ (q^-b + q^-bD/12b*MAXGAS_ALIGN)^(-1/b)

,GAS ~ (q^(1-b) - CUM_GASD/12(1-b)*q^-b)^(1/(1-b))

,mod_start = c(q = 45000, b = 0.9, D = 1.9)

,mod_start = X10WellTest_Seed ,.groups = "PROPNUM" ,output = "merge"

,est.name = "tgas"

,algorithm = "LM" )

The "X10WellTest" contains the data used as inputs to the model, the "X10WellTest_Seed" contains the starting values for the model inputs. I have pasted an Excel file with both data frames in separate tabs.

10WellSample_InputData.xlsx

m1mels73 commented 4 years ago

I just noticed the function did not paste correctly, the text editor truncated my multiplication symbols " * ". Adding a space break seemed to fix the problem.

CumMatch99 <- nls_table( X10WellTest ,GAS ~ (q^-b + q^-b D/12 b * MAXGAS_ALIGN)^(-1/b)

,GAS ~ (q^(1-b) - CUM_GAS D/12 (1-b) * q^-b)^(1/(1-b))

,mod_start = c(q = 45000, b = 0.9, D = 1.9)

,mod_start = X10WellTest_Seed ,.groups = "PROPNUM" ,output = "merge"

,est.name = "tgas"

,algorithm = "LM" )

sollano commented 3 years ago

Hi @m1mels73 , did you manage to get your model to work? I was pretty caught up in my work, and only now I'm having the time to look into these issues again.