预测R中的函数

时间:2016-09-16 00:17:49

标签: r regression predict nls non-linear-regression

我试图用predict函数来预测100分新点。我有一个data.frame,其中一个向量长100倍。

我正在尝试预测功能:predict(model, newdata=mydat)

该函数仅返回长度为4的向量。 这可能是因为模型只有四点,但我不确定。

编辑:

创建mydat

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

我正在使用的模型

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:修正拼写错误

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)

1 个答案:

答案 0 :(得分:1)

如果您的数据仍然在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))

然后我无法重现你的问题:

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

y <- predict(model, mydat)

length(y)
# [1] 100