Displaying 1 result from an estimated 1 matches for "peabov".
Did you mean:
peabove
2006 Aug 02
0
Trying to use segmented in a function
...most people use for
this, as far as I can see.
Since I want to run some simulations, I'm trying to write functions
that use segmented, and it's driving me mad. Here's a simple example:
simdata<-function
(Ns=200,Xmean=20,Xsd=5,SdYerr=0.5,Yint=0,threshold=20,slopebelow=0.5,slo
peabove=1)
{
Xs<-rnorm(Ns,Xmean,Xsd)
Yerr<-rnorm(Ns,0,SdYerr)
D<-ifelse(Xs<=threshold,0,1)
XminusX0<-Xs-threshold
Ys<-Yint+slopebelow*Xs+slopeabove*XminusX0*D+Yerr
plot(Xs,Ys)
linmod<-lm(Ys~Xs)
segment<-segmented(linmod,Z=Xs,psi=threshold)
segment
}
This code should...