How to add weightings in pspline:: smooth.Pspline R equivalent of MATLAB's csaps()What is the R equivalent of matlab's csaps()How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)What is the equivalent of MATLAB's repmat in NumPyHow to make a great R reproducible exampleCan I adjust spectogram frequency axes?Conceptual issues on training neural network wih particle swarm optimizationPlotting measured data along with Bode plotObtain degrees of freedom of each predictor variable in R-package mboostPlotting splines with confidence intervals on top of data pointsCan't plot smooth spline in R
Raw curve25519 public key points
What exactly makes a General Products hull nearly indestructible?
Why is DC so, so, so Democratic?
Can 々 stand for a duplicated kanji with a different reading?
How can I make sure my players' decisions have consequences?
I have a domain, static IP address and many devices I'd like to access outside my house. How do I route them?
Why did modems have speakers?
What is the best word describing the nature of expiring in a short amount of time, connoting "losing public attention"?
Killing a star safely
What is a "staved" town, like in "Staverton"?
What would be the side effects on the life of a person becoming indestructible?
Character Arcs - What if the character doesn't overcome the big lie, flaws or wounds?
Can GPL and BSD licensed applications be used for government work?
How could Barty Crouch Jr. have run out of Polyjuice Potion at the end of the Goblet of Fire movie?
Can a 14th level Theurgy Wizard with the Arcana Domain cast their 8th/9th level spells after picking up three levels in another Full Caster class?
How to make this script shorter?
Is an easily guessed plot twist a good plot twist?
Why can't a country print its own money to spend it only abroad?
Considerations when providing money to one child now, and the other later?
Company requiring me to let them review research from before I was hired
Inverse Colombian Function
Was US film used in Luna 3?
Are irregular workouts through the day effective?
Download file from URL to Safehouse
How to add weightings in pspline:: smooth.Pspline R equivalent of MATLAB's csaps()
What is the R equivalent of matlab's csaps()How to sort a dataframe by multiple column(s)How to join (merge) data frames (inner, outer, left, right)What is the equivalent of MATLAB's repmat in NumPyHow to make a great R reproducible exampleCan I adjust spectogram frequency axes?Conceptual issues on training neural network wih particle swarm optimizationPlotting measured data along with Bode plotObtain degrees of freedom of each predictor variable in R-package mboostPlotting splines with confidence intervals on top of data pointsCan't plot smooth spline in R
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to replicate Matlabs csaps function in r. I have successfully achieved this with this question.
However problems arise when I try to change the weightings in both cases. In MATLAB the weightings are based on the error measure however I am unsure what the w values correspond to in pspline function in r and it gives me a different result
https://uk.mathworks.com/help/curvefit/csaps.html
Here is some example code:
----------------IN MATLAB------------------
% Run spline with weights = 1
Axis = 1:100;
Yval = sin((1:100)/20 *(2*pi));
weights = ones(size(Yval));
p = 0.0005;
pp = csaps(Axis, Yval, p, [], weights);
smoothed = fnval(pp, Axis)';
% Run spline with some select weights = 0
weights([5,8,10,15,17,19,24,...
26,28,33,36,40,44,46,...
49,50,55,60,64,68,74,...
79,81,85,88,93,99,100])=0
pp2 = csaps(Axis, Yval, p, [], weights);
smoothed2 = fnval(pp2, Axis)';
plot(Axis,Yval)
hold on
plot(Axis,smoothed)
plot(Axis,smoothed2)
----------------IN R------------------
% Run spline with weights = 1
Axis <- 1:100
Yval <- sin((1:100)/20 *(2*pi))
weights <- rep(1,length(Yval))
p <- 0.0005
pp <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed <- c(predict(pp,Axis))
% Run spline with some select weights = 0
weights[c(5,8,10,15,17,19,24,
26,28,33,36,40,44,46,
49,50,55,60,64,68,74,
79,81,85,88,93,99,100)] <- 0.00000000000000001
pp2 <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed2 <- c(predict(pp2,Axis))
plot(Yval,t='l')
lines(smoothed,col = 2)
lines(smoothed2,col = 3)
The results in R and Matlab are identical (within rounding) without weightings, but when weights are introduced the results now differ. Both are running FORTRAN spline functions under the hood. I cant work out how to run pspline in R to get the same results with these weightings.
Thanks in advance!
r matlab
add a comment |
I am trying to replicate Matlabs csaps function in r. I have successfully achieved this with this question.
However problems arise when I try to change the weightings in both cases. In MATLAB the weightings are based on the error measure however I am unsure what the w values correspond to in pspline function in r and it gives me a different result
https://uk.mathworks.com/help/curvefit/csaps.html
Here is some example code:
----------------IN MATLAB------------------
% Run spline with weights = 1
Axis = 1:100;
Yval = sin((1:100)/20 *(2*pi));
weights = ones(size(Yval));
p = 0.0005;
pp = csaps(Axis, Yval, p, [], weights);
smoothed = fnval(pp, Axis)';
% Run spline with some select weights = 0
weights([5,8,10,15,17,19,24,...
26,28,33,36,40,44,46,...
49,50,55,60,64,68,74,...
79,81,85,88,93,99,100])=0
pp2 = csaps(Axis, Yval, p, [], weights);
smoothed2 = fnval(pp2, Axis)';
plot(Axis,Yval)
hold on
plot(Axis,smoothed)
plot(Axis,smoothed2)
----------------IN R------------------
% Run spline with weights = 1
Axis <- 1:100
Yval <- sin((1:100)/20 *(2*pi))
weights <- rep(1,length(Yval))
p <- 0.0005
pp <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed <- c(predict(pp,Axis))
% Run spline with some select weights = 0
weights[c(5,8,10,15,17,19,24,
26,28,33,36,40,44,46,
49,50,55,60,64,68,74,
79,81,85,88,93,99,100)] <- 0.00000000000000001
pp2 <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed2 <- c(predict(pp2,Axis))
plot(Yval,t='l')
lines(smoothed,col = 2)
lines(smoothed2,col = 3)
The results in R and Matlab are identical (within rounding) without weightings, but when weights are introduced the results now differ. Both are running FORTRAN spline functions under the hood. I cant work out how to run pspline in R to get the same results with these weightings.
Thanks in advance!
r matlab
5
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
3
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21
add a comment |
I am trying to replicate Matlabs csaps function in r. I have successfully achieved this with this question.
However problems arise when I try to change the weightings in both cases. In MATLAB the weightings are based on the error measure however I am unsure what the w values correspond to in pspline function in r and it gives me a different result
https://uk.mathworks.com/help/curvefit/csaps.html
Here is some example code:
----------------IN MATLAB------------------
% Run spline with weights = 1
Axis = 1:100;
Yval = sin((1:100)/20 *(2*pi));
weights = ones(size(Yval));
p = 0.0005;
pp = csaps(Axis, Yval, p, [], weights);
smoothed = fnval(pp, Axis)';
% Run spline with some select weights = 0
weights([5,8,10,15,17,19,24,...
26,28,33,36,40,44,46,...
49,50,55,60,64,68,74,...
79,81,85,88,93,99,100])=0
pp2 = csaps(Axis, Yval, p, [], weights);
smoothed2 = fnval(pp2, Axis)';
plot(Axis,Yval)
hold on
plot(Axis,smoothed)
plot(Axis,smoothed2)
----------------IN R------------------
% Run spline with weights = 1
Axis <- 1:100
Yval <- sin((1:100)/20 *(2*pi))
weights <- rep(1,length(Yval))
p <- 0.0005
pp <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed <- c(predict(pp,Axis))
% Run spline with some select weights = 0
weights[c(5,8,10,15,17,19,24,
26,28,33,36,40,44,46,
49,50,55,60,64,68,74,
79,81,85,88,93,99,100)] <- 0.00000000000000001
pp2 <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed2 <- c(predict(pp2,Axis))
plot(Yval,t='l')
lines(smoothed,col = 2)
lines(smoothed2,col = 3)
The results in R and Matlab are identical (within rounding) without weightings, but when weights are introduced the results now differ. Both are running FORTRAN spline functions under the hood. I cant work out how to run pspline in R to get the same results with these weightings.
Thanks in advance!
r matlab
I am trying to replicate Matlabs csaps function in r. I have successfully achieved this with this question.
However problems arise when I try to change the weightings in both cases. In MATLAB the weightings are based on the error measure however I am unsure what the w values correspond to in pspline function in r and it gives me a different result
https://uk.mathworks.com/help/curvefit/csaps.html
Here is some example code:
----------------IN MATLAB------------------
% Run spline with weights = 1
Axis = 1:100;
Yval = sin((1:100)/20 *(2*pi));
weights = ones(size(Yval));
p = 0.0005;
pp = csaps(Axis, Yval, p, [], weights);
smoothed = fnval(pp, Axis)';
% Run spline with some select weights = 0
weights([5,8,10,15,17,19,24,...
26,28,33,36,40,44,46,...
49,50,55,60,64,68,74,...
79,81,85,88,93,99,100])=0
pp2 = csaps(Axis, Yval, p, [], weights);
smoothed2 = fnval(pp2, Axis)';
plot(Axis,Yval)
hold on
plot(Axis,smoothed)
plot(Axis,smoothed2)
----------------IN R------------------
% Run spline with weights = 1
Axis <- 1:100
Yval <- sin((1:100)/20 *(2*pi))
weights <- rep(1,length(Yval))
p <- 0.0005
pp <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed <- c(predict(pp,Axis))
% Run spline with some select weights = 0
weights[c(5,8,10,15,17,19,24,
26,28,33,36,40,44,46,
49,50,55,60,64,68,74,
79,81,85,88,93,99,100)] <- 0.00000000000000001
pp2 <- pspline::smooth.Pspline(
x = Axis, y =Yval, w = weights, spar = (1-p) / p )
smoothed2 <- c(predict(pp2,Axis))
plot(Yval,t='l')
lines(smoothed,col = 2)
lines(smoothed2,col = 3)
The results in R and Matlab are identical (within rounding) without weightings, but when weights are introduced the results now differ. Both are running FORTRAN spline functions under the hood. I cant work out how to run pspline in R to get the same results with these weightings.
Thanks in advance!
r matlab
r matlab
edited Apr 1 at 11:19
Dan Lighter
asked Mar 26 at 15:08
Dan LighterDan Lighter
11 bronze badge
11 bronze badge
5
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
3
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21
add a comment |
5
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
3
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21
5
5
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
3
3
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21
add a comment |
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
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
);
);
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%2f55360451%2fhow-to-add-weightings-in-pspline-smooth-pspline-r-equivalent-of-matlabs-csaps%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55360451%2fhow-to-add-weightings-in-pspline-smooth-pspline-r-equivalent-of-matlabs-csaps%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
5
can you show us some code?
– LuckyLikey
Mar 26 at 15:12
3
Welcome to SO! Please edit your question to give a minimal reproducible example.
– jogo
Mar 26 at 15:19
Sorry for the delay, I have attached an example to run to show the difference. Thanks
– Dan Lighter
Apr 1 at 11:21