Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLS code #5

Open
docni opened this issue Oct 7, 2016 · 3 comments
Open

PLS code #5

docni opened this issue Oct 7, 2016 · 3 comments
Assignees

Comments

@docni
Copy link

docni commented Oct 7, 2016

Dear Kirstie,

Can I check regarding the PLS_calculate_stats matlab code.

For the line;

[R1,p1]=corr([XS(:,1),XS(:,2)],MRIdata);
if R1(1,2)<0
XS(:,1)=-1_XS(:,1);
end
if R1(2,4)<0
XS(:,2)=-1_XS(:,2);
end

I am assuming this is running the analysis looking for how MT and dMT explain the variance in gene expression, as there are the 2nd and 4th variable in the csv file.

Thus if I only had two mri variables in my spread sheet I would change to?;

[R1,p1]=corr([XS(:,1),XS(:,2)],MRIdata);
if R1(1,1)<0
XS(:,1)=-1_XS(:,1);
end
if R1(2,2)<0
XS(:,2)=-1_XS(:,2);
end

And if I wanted to look at three response variables, how would I alter it?

Thanks again for all your help.

bw

Peter

@KirstieJane
Copy link
Owner

KirstieJane commented Oct 7, 2016

Hi @docni ,

Thanks for asking.

The two columns in the PLS_calculate_stats.m code relate to the two PLS components (in this code we only ask for the first 2 components using dim=2. You could easily change that number to see what how many PLS components made sense for your analysis.)

The code you quote:

%align PLS components with desired direction%
[R1,p1]=corr([XS(:,1),XS(:,2)],MRIdata);
if R1(1,2)<0
XS(:,1)=-1XS(:,1);
end
if R1(2,4)<0
XS(:,2)=-1XS(:,2);
end

Is correlating the predicted scores for the two pls components XS(:,1) and XS(:,2) and correlating them with the input MRIdata.

(We actually do that again more explicitly in the code below)

%calculate correlations of PLS components with MRI variables
[R1,p1]=corr(XS(:,1),MRIdata);
[R2,p2]=corr(XS(:,2),MRIdata);
a=[R1',p1',R2',p2'];

But back to the point.

If the PLS component is negatively correlated with the MRIdata then we flip the sign of the component (by multiplying by -1).

The reason we do this step is to help interpret the components. The direction is essentially arbitrary but if the components are aligned it helps to see if they have opposing effects (for example).

@docni
Copy link
Author

docni commented Oct 7, 2016

Thanks so much Kirstie, this is very helpful!

bw

Peter


From: Kirstie Whitaker notifications@github.com
Sent: 07 October 2016 09:42:56
To: KirstieJane/NSPN_WhitakerVertes_PNAS2016
Cc: Peter McColgan; Mention
Subject: Re: [KirstieJane/NSPN_WhitakerVertes_PNAS2016] PLS code (#5)

Hi @docnihttps://github.com/docni ,

Thanks for asking.

Actually, the two columns in the PLS_calculate_stats.mhttps://github.com/KirstieJane/NSPN_WhitakerVertes_PNAS2016/blob/master/SCRIPTS/PLS_calculate_stats.m code relate to the two PLS components (in this code we only ask for the first 2 components using dim=2. You could easily change that number to see what how many PLS components made sense for your analysis.)

The code you quote:

%align PLS components with desired direction%
[R1,p1]=corr([XS(:,1),XS(:,2)],MRIdata);
if R1(1,2)<0
XS(:,1)=-1XS(:,1);
end
if R1(2,4)<0
XS(:,2)=-1XS(:,2);
end

Is correlating the predicted scores for the two pls components XS(:,1) and XS(:,2) and correlating them with the input MRIdata.

(It's actually somewhat redundant with the code below)

%calculate correlations of PLS components with MRI variables
[R1,p1]=corr(XS(:,1),MRIdata);
[R2,p2]=corr(XS(:,2),MRIdata);
a=[R1',p1',R2',p2'];

But back to the point.

If the PLS component is negatively correlated with the MRIdata then we flip the sign of the component (by multiplying by -1).

The reason we do this step is to help interpret the components. The direction is essentially arbitrary but if the components are aligned it helps to see if they have opposing effects (for example).

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/5#issuecomment-252184972, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AVXMCJHVtkwzpo4zLGV4F1saMzlveYllks5qxgYQgaJpZM4KQwet.

@KirstieJane KirstieJane self-assigned this Oct 7, 2016
@KirstieJane
Copy link
Owner

To do for @KirstieJane:

  • Check with Petra that I'm right! (update: correct - phew! 🎉)
  • Add this answer to documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants