首先,我有你的载体,
x.seq
对于x
,Fm
和x
的平滑向量是确定向量x.seq <- seq(qjx[1],qjx[m+1],by=0.01)
Fm <- function(data,x){ #data = smooth data, x = intial data
x.smooth <- NULL;
xsmooth <- matrix(,nrow=(length(x)),ncol=length(data))
xsmooth. <- matrix(,nrow=(length(x)),ncol=length(data))
for(i in 1:m){
for(j in 1:length(data)){
xsmooth[i,j] <- (data[j] - qjx[i])/rjx[i]
if(xsmooth[i,j] < 0){
xsmooth.[i,j] <- 0
} else
if(xsmooth[i,j] >= 0 && xsmooth[i,j] <= 1){
xsmooth.[i,j] = xsmooth[i,j]
} else
if(xsmooth[i,j] > 1){
xsmooth.[i,j] <- 1
}
}
}
xsmoothing <- NULL
for(k in 1:ncol(xsmooth.)){
xsmoothing[k] <- mean(xsmooth.[,k])
}
print(as.numeric(xsmoothing))
}
的c.d.f值的函数
t
接下来我想用函数Fm
计算m <- length(x)
Finv <- function(t){
if(t > 0){
f.inv <- matrix(,ncol=2,nrow=m)
k <- 1;f.invers <- NULL
while(k <= m){
f.inv[k,1] <- (k-1)/m
f.inv[k,2] <- k/m
if(t >= f.inv[k,1] && t <= f.inv[k,2]){
f.invers[k] <- (((m*t)-(k-1))*rjx[k])+qjx[k]
} else
f.invers[k] <- NA
k <- k+1
}
hasil <- as.numeric(f.invers[!is.na(f.invers)])
print(hasil)
} else
hasil <- L # L = the initial value,for example L is 2.06
print(as.numeric(hasil))
}
的逆值,我的函数在这里
t
原因是为什么我做了这个功能,因为q
有许多序列。所以,我从1开始编译每个t
,直到t <- Fm(x.seq,x)
invers <- NULL
for(q in 1:length(t)){
print(invers[q] <- Finv(1-t[q]))
}
invers
Warning messages:
1: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
2: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
3: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
4: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
5: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
6: In invers[q] <- Finv(1 - t[q]) :
number of items to replace is not a multiple of replacement length
它工作正常,但在处理反转的值时,会有警告
foo
我只想知道反函数的错误在哪里。感谢
答案 0 :(得分:0)
在t之后尝试这个,
invers<-vector()
invers <- NULL
for(q in 1:(length(t)-1)){
invers<-c(invers,Finv(1-t[q]))
}
invers
我将测试这个:
invers <- NULL
for(q in 1:(length(t))){
invers<-c(invers,Finv(1-t[q]))
}
invers
invers1<-vector()
invers1 <- NULL
for(q in 1:(length(t)-1)){
invers1<-c(invers,Finv(1-t[q]))
}
invers1
which(invers[1:1134]!=invers1[1:1134])
这是控制台的结果。
> which(invers[1:1134]!=invers1[1:1134])
integer(0)