Nicholas Hayden - 1 year ago 76

R Question

I am trying to use to

`predict`

`data.frame`

I am trying the predict function:

`predict(model, newdata=mydat)`

The function only returns a vector of length four.

This could be due to the fact that the model was made only with four points, but I am unsure.

Creation of mydat

`mydat <- data.frame(V1 = seq(0, max(myExperimentSummary$V1), length.out = 100))`

The model I am using

`model`

#Nonlinear regression model

# model: mean ~ (1/(1 + exp(-b * (V1 - c))))

# data: myExperimentSummary

# b c

#-0.6721 3.2120

# residual sum-of-squares: 0.04395

#

#Number of iterations to convergence: 1

#Achieved convergence tolerance: 5.204e-06

`fitcoef = nlsLM(mean~(a/(1+exp(-b*(V5-c)))), data = myExperimentSummary,`

start=c(a=1,b=.1,c=25))

fitmodel = nls(mean~(1/(1+exp(-b*(V1-c)))), data = myExperimentSummary,

start=coef(fitcoef))

mydat <- data.frame(V1 = seq(0, max(myExperimentSummary$V1), length.out = 100))

predict(fitmodel, mydat)

Answer Source

If your data are still as in your previous question:

```
dat <- read.table(text = " V1 N mean
0.1 9 0.9
1 9 0.8
10 9 0.1
5 9 0.2",
header = TRUE)
model <- nls(mean ~ -a/(1 + exp(-b * (V1-o))), data = dat,
start=list(a=-1.452, b=-0.451, o=1.292))
```

Then I can not reproduce your problem:

```
mydat <- data.frame(V1 = seq(0, max(dat$V1), length.out = 100))
y <- predict(model, mydat)
length(y)
# [1] 100
```