Hi, I?m contacting you because I have some trouble with the slope() function of segmented. When I plot the predicted value everything seems to have worked well. But when I use slope(), the slope for the first segment is a line with 0 and Nas? Also I can get a negative slope whereas on the graph it?s clearly a positive slope? Here are the lines I?m using : Mod = lm(as.numeric(data[,"meanMSD25"])~(as.numeric(data[,"Slice"])), weights=1*sqrt(as.numeric(data[,"Detec"]))) x = (as.numeric(data[,"Slice"])) o <- segmented(Mod, seg.Z=~x, psi=NA, control=seg.control(display=FALSE, K=2)) Thanks in advance for your help, Best regards, M?lina COINTE [[alternative HTML version deleted]]
Hi M?lina, If you don't get an answer here, consider running maintainer(segmented) and contacting the e-mail address shown by the command. On Tue, 8 Mar 2022 20:44:35 +0000 M?lina Cointe <melina.cointe at outlook.fr> wrote:> I have some trouble with the slope() function of segmented. When I > plot the predicted value everything seems to have worked well. But > when I use slope(), the slope for the first segment is a line with 0 > and Nas_ Also I can get a negative slope whereas on the graph it_s > clearly a positive slope_It would help if you show us a small sample of your data. Use dput() to produce a plain text representation of it. Otherwise it's next to impossible to reproduce the problems you're having.> [[alternative HTML version deleted]]When you post in HTML, the list removes the HTML version for safety reasons, and all we're left with is the plain text version automatically prepared by your mailer. This plain text version can be severely mangled and hard to understand. Please post in plain text: http://www.R-project.org/posting-guide.html -- Best regards, Ivan
Hi 1. Do not use HTML formated mail, your message is scrambled 2. With your code only you can get result all of us get error> Mod = lm(as.numeric(data[,"meanMSD25"])~(as.numeric(data[,"Slice"])), weights=1*sqrt(as.numeric(data[,"Detec"])))Error in data[, "meanMSD25"] : object of type 'closure' is not subsettable Try to provide reproducible example. 3. with lm it is not necessary to use data[,"meanMSD25"], you should provide your data object to data option in lm call (it is silly to call your data data - fortune("dog") applies here) 4. why do you use as.numeric(data[,"meanMSD25"]), shouldn't the column be numeric itself? So my wild guess is that you read the data into R wrong way and instead of numeric they are character, which could be one source of your problem. Cheers Petr> -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of M?lina Cointe > Sent: Tuesday, March 8, 2022 9:45 PM > To: r-help at r-project.org > Subject: Re: [R] NA's in segmented > > Hi, > > I?m contacting you because I have some trouble with the slope() function of > segmented. When I plot the predicted value everything seems to have worked > well. But when I use slope(), the slope for the first segment is a line with 0 > and Nas? Also I can get a negative slope whereas on the graph it?s clearly a > positive slope? > > Here are the lines I?m using : > > Mod = lm(as.numeric(data[,"meanMSD25"])~(as.numeric(data[,"Slice"])), > weights=1*sqrt(as.numeric(data[,"Detec"]))) > x = (as.numeric(data[,"Slice"])) > o <- segmented(Mod, seg.Z=~x, psi=NA, control=seg.control(display=FALSE, > K=2)) > > Thanks in advance for your help, > > Best regards, > > M?lina COINTE > > > > [[alternative HTML version deleted]]