0

I am having an issue with the segmented package in R. The issue is when I use the davies.test and segmented.default. The code I am working with is as follows:

library(segmented)
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
o<-svyglm(api00~ell, design=dstrat)
#specify as a string the objective function to be minimized. It can be obtained via svyvar() 
fn.x<- 'as.numeric(svyvar(resid(x, "pearson"), x$survey.design, na.rm = TRUE))'
os<-segmented.default(o, ~ell, control=seg.control(fn.obj=fn.x, display=TRUE))
slope(os)
davies.test(os, ~ell)

I get this error: Error in eval(predvars, data, env) : object 'api00' not found. I am new to the segmented package and I do not know how to fix this. I tried the svyglm object "o" and I still get the same error. What am I missing?

Edward
22.3k3 gold badges18 silver badges37 bronze badges
asked Oct 2, 2024 at 1:04
4
  • It looks like the segmented package doesn't support survey models that use svyglm. Commented Oct 2, 2024 at 2:54
  • I thought "api00" was the name of a dataframe. If I’m wrong then you haven’t loaded the dataset. Commented Oct 2, 2024 at 3:51
  • hi, not sure if it's helpful but here's a replication of a cdc analysis that uses library(segmented) with complex sample survey data.. Commented Oct 2, 2024 at 13:29
  • This is helpful. Thank you Commented Oct 9, 2024 at 21:51

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.