0
votes

so I'm new to data science using R and I'm not sure what I'm doing wrong here. using the data set:

rocketBurn Oxygen Consumed Hydrogen Used Trajectory Thrust
20 20000 30000 0 500000
40 40000 60000 0 525000
60 60000 90000 0 551250
80 80000 120000 4 578813
100 100000 150000 8 593283
120 120000 180000 12 593283
140 140000 210000 16 593283
160 160000 240000 20 593283
180 180000 270000 24 593283
200 200000 300000 28 593283
220 220000 330000 32 593283
240 240000 360000 36 593283
260 260000 390000 40 593283
280 280000 420000 44 593283
300 300000 450000 46 593283
320 320000 480000 46 593283

I was able to create the linear regression model using the lm() formula in R, when I try to use the nls formula I am recieing the following error message

nlrModel <- nls(Trajectory ~ Oxygen.Consumed + Thrust,data = df,start = c(a=0,b=0,c=0))
Error in nlsModel(formula, mf, start, wts, scaleOffset = scOff, nDcentral = nDcntr) : 
 singular gradient matrix at initial parameter estimates

After some googling I believe the error is due to the start parms, however, I don't know how to get the correct start parm. Any help on how to get this model to work would be greatly appreciated!

1
Let us start with, What is the equation you are trying to fit? Since "Oxygen" + "Thrust" is not a realistic formula to equal "Trajectory".Dave2e
this is the linear model I created, the ask was to create a model using these variables. if I shouldn't be using it the way I am can you please explain why and what I should do?Kyle Hollander
Residuals: Min 1Q Median 3Q Max -4.1001 -0.3476 0.3379 1.0271 1.8617 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.263e+01 1.176e+01 1.925 0.0764 . Oxygen.Consumed 1.908e-04 6.502e-06 29.344 2.88e-13 *** Thrust -5.662e-05 2.156e-05 -2.626 0.0209 * --- Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.708 on 13 degrees of freedom Multiple R-squared: 0.9914, Adjusted R-squared: 0.9901 F-statistic: 749.2 on 2 and 13 DF, p-value: 3.755e-14Kyle Hollander
Call: lm(formula = Trajectory ~ Oxygen.Consumed + Thrust, data = df)Kyle Hollander
If you want to a linear module such as aOxygen + bThrust + c then use the lm() function. Only when your equation is non-linear should you consider using nls() [nonlinear least squares] function!! Since you were able to obtain a result with lm I am not understanding the question.Dave2e

1 Answers

0
votes

The problem is that the formula in the nls model is wrong. lm and nls do not use the same formula notation. In lm for a model with no interactions the independent variables are listed separated by plus signs whereas in nls the formula includes the coefficients. For example, this describes the same model in lm and nls.

lm(Trajectory ~ Oxygen.Consumed + Thrust, df)

st <- list(a = 1, b = 1, c = 1)
nls(Trajectory ~ a + b * Oxygen.Consumed + c * Thrust, df, start = st)

Note

The input in reproducible form is:

df <- 
structure(list(rocketBurn = c(20L, 40L, 60L, 80L, 100L, 120L, 
140L, 160L, 180L, 200L, 220L, 240L, 260L, 280L, 300L, 320L), 
    Oxygen.Consumed = c(20000L, 40000L, 60000L, 80000L, 100000L, 
    120000L, 140000L, 160000L, 180000L, 200000L, 220000L, 240000L, 
    260000L, 280000L, 300000L, 320000L), Hydrogen.Used = c(30000L, 
    60000L, 90000L, 120000L, 150000L, 180000L, 210000L, 240000L, 
    270000L, 300000L, 330000L, 360000L, 390000L, 420000L, 450000L, 
    480000L), Trajectory = c(0L, 0L, 0L, 4L, 8L, 12L, 16L, 20L, 
    24L, 28L, 32L, 36L, 40L, 44L, 46L, 46L), Thrust = c(500000L, 
    525000L, 551250L, 578813L, 593283L, 593283L, 593283L, 593283L, 
    593283L, 593283L, 593283L, 593283L, 593283L, 593283L, 593283L, 
    593283L)), class = "data.frame", row.names = c(NA, -16L))