0

以下のデータ付きの私のRコードを見てください

channelName = as.character(myData$TV_total[1])
maxX = 1.05*max(myData$TV_total)
maxY = 1.05*max(myData$Total)



myPlotDataDF = data.frame(Return = myData$Total, Spend = myData$TV_total)


simpleScatterPlot <- ggplot(myPlotDataDF, aes(x = Spend, y = Return)) +
  geom_point(color="black") +
  theme(panel.background = element_rect(fill = 'grey85'),
        panel.grid.major = element_line(colour = "white")) +
  coord_cartesian(ylim = c(0,maxY), xlim = c(0,maxX)) +
  scale_x_continuous(labels = dollar) +
  scale_y_continuous(labels = comma) + 
  ggtitle(paste(channelName))

simpleScatterPlot 

girafe(ggobj = simpleScatterPlot)


Ufun<-function(x, Spend, Return) {
  predictedReturn = x[2] + (x[1] - x[2])*((Spend^x[3])/(x[4] + (Spend^x[3])))
  errorSq = (predictedReturn - Return)^2
  sumSqError = sum(errorSq)
  return(sumSqError)
}


startValVec = c(25000,100,1.5,100000)
minValVec = c(0,0,1.01,1)
maxValVec = c(500000, 500000, 2, 100000)


optim.parms<-nlminb(objective=Ufun,start=startValVec,
                    lower=minValVec,
                    upper=maxValVec,
                    control=list(iter.max=100000,eval.max=2000),
                    Spend = myData$Spend,
                    Return = myData$Return)

optim.parms

a = optim.parms$par[1]
b = optim.parms$par[2]
c = optim.parms$par[3]
d = optim.parms$par[4]

curveDFx = seq(from=0, to=max(myData$Spend)*2, length.out=10000)
curveDFy = b+(a-b)*((curveDFx^c)/(d+(curveDFx^c)))
curveDF = data.frame(Spend = curveDFx, Return = curveDFy)

次に、エラーがスローされます

seq.default(from = 1, to = max(myData$Spend) * 2, length.out = 10000) のエラー: 'to' は有限数でなければなりません さらに: 警告メッセージ: max(myData$Spend) 内: max に欠落していない引数はありません。-Inf を返す

4

1 に答える 1