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?
r modeling effects rcs
add a comment |
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?
r modeling effects rcs
I would have expected that Predict or predict would give you what you expect. Therms
planet is not in orbit around theeffects
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
add a comment |
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?
r modeling effects rcs
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
r modeling effects rcs
asked Nov 10 at 22:35
Dan Villarreal
606
606
I would have expected that Predict or predict would give you what you expect. Therms
planet is not in orbit around theeffects
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
add a comment |
I would have expected that Predict or predict would give you what you expect. Therms
planet is not in orbit around theeffects
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
add a comment |
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
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 thes()
function and supports mixed effects.
– 42-
Nov 11 at 0:29
add a comment |
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
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 thes()
function and supports mixed effects.
– 42-
Nov 11 at 0:29
add a comment |
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
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 thes()
function and supports mixed effects.
– 42-
Nov 11 at 0:29
add a comment |
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
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
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 thes()
function and supports mixed effects.
– 42-
Nov 11 at 0:29
add a comment |
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 thes()
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I would have expected that Predict or predict would give you what you expect. The
rms
planet is not in orbit around theeffects
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