Get fitted effects from a model with an rcs term











up vote
0
down vote

favorite












I would like to get fitted values from a linear model that includes a restricted cubic spline term fit via rms::rcs(), to pass into an effects plot. The issue is that the package I typically use to get fitted values, effects, throws an error when I try to pass a model with an rcs term.



Here's a minimal reprex:



library(rms)
library(effects)
mod <- lm(Sepal.Length ~ rcs(Sepal.Width, 3), iris)
Effect("Sepal.Width", mod)
##Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) : knots not specified, and < 6 non-missing observations


I have tried debugging this error, but I can't arrive at how rcspline.eval() got 6+ NAs in x and non-specified nknots. How do I deal with this error? Alternatively, is there another package out there that can get fitted effects from a model with an rcs term?










share|improve this question






















  • I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
    – 42-
    Nov 10 at 23:28












  • Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
    – Dan Villarreal
    Nov 10 at 23:30















up vote
0
down vote

favorite












I would like to get fitted values from a linear model that includes a restricted cubic spline term fit via rms::rcs(), to pass into an effects plot. The issue is that the package I typically use to get fitted values, effects, throws an error when I try to pass a model with an rcs term.



Here's a minimal reprex:



library(rms)
library(effects)
mod <- lm(Sepal.Length ~ rcs(Sepal.Width, 3), iris)
Effect("Sepal.Width", mod)
##Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) : knots not specified, and < 6 non-missing observations


I have tried debugging this error, but I can't arrive at how rcspline.eval() got 6+ NAs in x and non-specified nknots. How do I deal with this error? Alternatively, is there another package out there that can get fitted effects from a model with an rcs term?










share|improve this question






















  • I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
    – 42-
    Nov 10 at 23:28












  • Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
    – Dan Villarreal
    Nov 10 at 23:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I would like to get fitted values from a linear model that includes a restricted cubic spline term fit via rms::rcs(), to pass into an effects plot. The issue is that the package I typically use to get fitted values, effects, throws an error when I try to pass a model with an rcs term.



Here's a minimal reprex:



library(rms)
library(effects)
mod <- lm(Sepal.Length ~ rcs(Sepal.Width, 3), iris)
Effect("Sepal.Width", mod)
##Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) : knots not specified, and < 6 non-missing observations


I have tried debugging this error, but I can't arrive at how rcspline.eval() got 6+ NAs in x and non-specified nknots. How do I deal with this error? Alternatively, is there another package out there that can get fitted effects from a model with an rcs term?










share|improve this question













I would like to get fitted values from a linear model that includes a restricted cubic spline term fit via rms::rcs(), to pass into an effects plot. The issue is that the package I typically use to get fitted values, effects, throws an error when I try to pass a model with an rcs term.



Here's a minimal reprex:



library(rms)
library(effects)
mod <- lm(Sepal.Length ~ rcs(Sepal.Width, 3), iris)
Effect("Sepal.Width", mod)
##Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc, fractied = fractied) : knots not specified, and < 6 non-missing observations


I have tried debugging this error, but I can't arrive at how rcspline.eval() got 6+ NAs in x and non-specified nknots. How do I deal with this error? Alternatively, is there another package out there that can get fitted effects from a model with an rcs term?







r modeling effects rcs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 22:35









Dan Villarreal

606




606












  • I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
    – 42-
    Nov 10 at 23:28












  • Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
    – Dan Villarreal
    Nov 10 at 23:30


















  • I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
    – 42-
    Nov 10 at 23:28












  • Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
    – Dan Villarreal
    Nov 10 at 23:30
















I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
– 42-
Nov 10 at 23:28






I would have expected that Predict or predict would give you what you expect. The rms planet is not in orbit around the effects center of gravity.
– 42-
Nov 10 at 23:28














Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
– Dan Villarreal
Nov 10 at 23:30




Can you give an example as an answer? I looked into predict but couldn't wrap my head around how to make it work.
– Dan Villarreal
Nov 10 at 23:30












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Users of the rms environment will need to use the specialized functions that support its activities:



 library(rms)
ddist <- datadist(iris) # need both datadist and options
options(datadist='ddist')
mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris) # need ols rather than lm
plot( Predict(mod, Sepal.Width)) # Predict can be done in 2 or 3 dimension
# gives a lattice output


enter image description here






share|improve this answer





















  • I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
    – Dan Villarreal
    Nov 10 at 23:55










  • So you posed a question that didn't include the essential criteria.
    – 42-
    Nov 10 at 23:58










  • I didn't know where the sticking point would be. You did answer the question, so I'll accept.
    – Dan Villarreal
    Nov 11 at 0:00






  • 1




    My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
    – 42-
    Nov 11 at 0:29













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244104%2fget-fitted-effects-from-a-model-with-an-rcs-term%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Users of the rms environment will need to use the specialized functions that support its activities:



 library(rms)
ddist <- datadist(iris) # need both datadist and options
options(datadist='ddist')
mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris) # need ols rather than lm
plot( Predict(mod, Sepal.Width)) # Predict can be done in 2 or 3 dimension
# gives a lattice output


enter image description here






share|improve this answer





















  • I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
    – Dan Villarreal
    Nov 10 at 23:55










  • So you posed a question that didn't include the essential criteria.
    – 42-
    Nov 10 at 23:58










  • I didn't know where the sticking point would be. You did answer the question, so I'll accept.
    – Dan Villarreal
    Nov 11 at 0:00






  • 1




    My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
    – 42-
    Nov 11 at 0:29

















up vote
1
down vote



accepted










Users of the rms environment will need to use the specialized functions that support its activities:



 library(rms)
ddist <- datadist(iris) # need both datadist and options
options(datadist='ddist')
mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris) # need ols rather than lm
plot( Predict(mod, Sepal.Width)) # Predict can be done in 2 or 3 dimension
# gives a lattice output


enter image description here






share|improve this answer





















  • I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
    – Dan Villarreal
    Nov 10 at 23:55










  • So you posed a question that didn't include the essential criteria.
    – 42-
    Nov 10 at 23:58










  • I didn't know where the sticking point would be. You did answer the question, so I'll accept.
    – Dan Villarreal
    Nov 11 at 0:00






  • 1




    My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
    – 42-
    Nov 11 at 0:29















up vote
1
down vote



accepted







up vote
1
down vote



accepted






Users of the rms environment will need to use the specialized functions that support its activities:



 library(rms)
ddist <- datadist(iris) # need both datadist and options
options(datadist='ddist')
mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris) # need ols rather than lm
plot( Predict(mod, Sepal.Width)) # Predict can be done in 2 or 3 dimension
# gives a lattice output


enter image description here






share|improve this answer












Users of the rms environment will need to use the specialized functions that support its activities:



 library(rms)
ddist <- datadist(iris) # need both datadist and options
options(datadist='ddist')
mod <- ols(Sepal.Length ~ rcs(Sepal.Width, 3), iris) # need ols rather than lm
plot( Predict(mod, Sepal.Width)) # Predict can be done in 2 or 3 dimension
# gives a lattice output


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 23:44









42-

210k14248391




210k14248391












  • I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
    – Dan Villarreal
    Nov 10 at 23:55










  • So you posed a question that didn't include the essential criteria.
    – 42-
    Nov 10 at 23:58










  • I didn't know where the sticking point would be. You did answer the question, so I'll accept.
    – Dan Villarreal
    Nov 11 at 0:00






  • 1




    My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
    – 42-
    Nov 11 at 0:29




















  • I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
    – Dan Villarreal
    Nov 10 at 23:55










  • So you posed a question that didn't include the essential criteria.
    – 42-
    Nov 10 at 23:58










  • I didn't know where the sticking point would be. You did answer the question, so I'll accept.
    – Dan Villarreal
    Nov 11 at 0:00






  • 1




    My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
    – 42-
    Nov 11 at 0:29


















I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
– Dan Villarreal
Nov 10 at 23:55




I see. I'm not sure if this solution will work for me since I ultimately want to apply this to a mixed-effects model, and AFAIK rms's builtin modeling functions don't allow random effects
– Dan Villarreal
Nov 10 at 23:55












So you posed a question that didn't include the essential criteria.
– 42-
Nov 10 at 23:58




So you posed a question that didn't include the essential criteria.
– 42-
Nov 10 at 23:58












I didn't know where the sticking point would be. You did answer the question, so I'll accept.
– Dan Villarreal
Nov 11 at 0:00




I didn't know where the sticking point would be. You did answer the question, so I'll accept.
– Dan Villarreal
Nov 11 at 0:00




1




1




My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
– 42-
Nov 11 at 0:29






My understanding is that the mgcv package provides cubic splines via the s() function and supports mixed effects.
– 42-
Nov 11 at 0:29




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244104%2fget-fitted-effects-from-a-model-with-an-rcs-term%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma