简体   繁体   中英

Predict function in R

I am trying to use to predict function to predict 100 points new points. I have a data.frame with one vector that is 100 doubls long.

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.

EDIT:

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

EDIT2: Fixing the typos

EDIT3:

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM