How do I make LinearModelFit flexible to number of parameters using FromLetterNumber?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I want to run LinearModelFit where the number of parameters is not fixed. For example, the following
i = 2;
data = RandomReal[20,10,3+i];
lm1 = LinearModelFit[data,FromLetterNumber[Range[2+i]],FromLetterNumber[Range[2+i]];
doesn't work, whereas
lm1 = LinearModelFit[data,a,b,c,d,a,b,c,d]
works as per described, despite FromLetterNumber[Range[2+i]] == a,b,c,d
Can this be made to work using some kind of Hold
or do I need to resort to a design matrix, response vector format?
fitting hold
add a comment |Â
up vote
4
down vote
favorite
I want to run LinearModelFit where the number of parameters is not fixed. For example, the following
i = 2;
data = RandomReal[20,10,3+i];
lm1 = LinearModelFit[data,FromLetterNumber[Range[2+i]],FromLetterNumber[Range[2+i]];
doesn't work, whereas
lm1 = LinearModelFit[data,a,b,c,d,a,b,c,d]
works as per described, despite FromLetterNumber[Range[2+i]] == a,b,c,d
Can this be made to work using some kind of Hold
or do I need to resort to a design matrix, response vector format?
fitting hold
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I want to run LinearModelFit where the number of parameters is not fixed. For example, the following
i = 2;
data = RandomReal[20,10,3+i];
lm1 = LinearModelFit[data,FromLetterNumber[Range[2+i]],FromLetterNumber[Range[2+i]];
doesn't work, whereas
lm1 = LinearModelFit[data,a,b,c,d,a,b,c,d]
works as per described, despite FromLetterNumber[Range[2+i]] == a,b,c,d
Can this be made to work using some kind of Hold
or do I need to resort to a design matrix, response vector format?
fitting hold
I want to run LinearModelFit where the number of parameters is not fixed. For example, the following
i = 2;
data = RandomReal[20,10,3+i];
lm1 = LinearModelFit[data,FromLetterNumber[Range[2+i]],FromLetterNumber[Range[2+i]];
doesn't work, whereas
lm1 = LinearModelFit[data,a,b,c,d,a,b,c,d]
works as per described, despite FromLetterNumber[Range[2+i]] == a,b,c,d
Can this be made to work using some kind of Hold
or do I need to resort to a design matrix, response vector format?
fitting hold
asked Aug 6 at 7:54
Thadeu Freitas Filho
866
866
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
FromLetterNumber
returns a String
:
Head @ FromLetterNumber @ 3
String
You can wrap the strings returned by FromLetterNumber
with Symbol
or ToExpression
to get Symbol
s:
lm1 = LinearModelFit[data, Symbol /@ FromLetterNumber[Range[2+i]],
Symbol /@ FromLetterNumber[Range[2+i]]];
Normal @ lm1
9.60642 + 0.175108 a - 0.723711 b + 0.850788 c - 0.198777 d
Alternatively,
lm2 = LinearModelFit[data, Array[a, 2 + i], Array[a, 2 + i] ] ;
Normal @ lm2
9.60642 + 0.175108 a[1] - 0.723711 a[2] + 0.850788 a[3] - 0.198777 a[4]
2
TheArray
version should be the canonical choice, IMHO. +1
â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
FromLetterNumber
returns a String
:
Head @ FromLetterNumber @ 3
String
You can wrap the strings returned by FromLetterNumber
with Symbol
or ToExpression
to get Symbol
s:
lm1 = LinearModelFit[data, Symbol /@ FromLetterNumber[Range[2+i]],
Symbol /@ FromLetterNumber[Range[2+i]]];
Normal @ lm1
9.60642 + 0.175108 a - 0.723711 b + 0.850788 c - 0.198777 d
Alternatively,
lm2 = LinearModelFit[data, Array[a, 2 + i], Array[a, 2 + i] ] ;
Normal @ lm2
9.60642 + 0.175108 a[1] - 0.723711 a[2] + 0.850788 a[3] - 0.198777 a[4]
2
TheArray
version should be the canonical choice, IMHO. +1
â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
add a comment |Â
up vote
5
down vote
accepted
FromLetterNumber
returns a String
:
Head @ FromLetterNumber @ 3
String
You can wrap the strings returned by FromLetterNumber
with Symbol
or ToExpression
to get Symbol
s:
lm1 = LinearModelFit[data, Symbol /@ FromLetterNumber[Range[2+i]],
Symbol /@ FromLetterNumber[Range[2+i]]];
Normal @ lm1
9.60642 + 0.175108 a - 0.723711 b + 0.850788 c - 0.198777 d
Alternatively,
lm2 = LinearModelFit[data, Array[a, 2 + i], Array[a, 2 + i] ] ;
Normal @ lm2
9.60642 + 0.175108 a[1] - 0.723711 a[2] + 0.850788 a[3] - 0.198777 a[4]
2
TheArray
version should be the canonical choice, IMHO. +1
â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
FromLetterNumber
returns a String
:
Head @ FromLetterNumber @ 3
String
You can wrap the strings returned by FromLetterNumber
with Symbol
or ToExpression
to get Symbol
s:
lm1 = LinearModelFit[data, Symbol /@ FromLetterNumber[Range[2+i]],
Symbol /@ FromLetterNumber[Range[2+i]]];
Normal @ lm1
9.60642 + 0.175108 a - 0.723711 b + 0.850788 c - 0.198777 d
Alternatively,
lm2 = LinearModelFit[data, Array[a, 2 + i], Array[a, 2 + i] ] ;
Normal @ lm2
9.60642 + 0.175108 a[1] - 0.723711 a[2] + 0.850788 a[3] - 0.198777 a[4]
FromLetterNumber
returns a String
:
Head @ FromLetterNumber @ 3
String
You can wrap the strings returned by FromLetterNumber
with Symbol
or ToExpression
to get Symbol
s:
lm1 = LinearModelFit[data, Symbol /@ FromLetterNumber[Range[2+i]],
Symbol /@ FromLetterNumber[Range[2+i]]];
Normal @ lm1
9.60642 + 0.175108 a - 0.723711 b + 0.850788 c - 0.198777 d
Alternatively,
lm2 = LinearModelFit[data, Array[a, 2 + i], Array[a, 2 + i] ] ;
Normal @ lm2
9.60642 + 0.175108 a[1] - 0.723711 a[2] + 0.850788 a[3] - 0.198777 a[4]
edited Aug 7 at 0:00
answered Aug 6 at 8:06
kglr
154k8179374
154k8179374
2
TheArray
version should be the canonical choice, IMHO. +1
â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
add a comment |Â
2
TheArray
version should be the canonical choice, IMHO. +1
â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
2
2
The
Array
version should be the canonical choice, IMHO. +1â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
The
Array
version should be the canonical choice, IMHO. +1â Marius LadegÃ¥rd Meyer
Aug 6 at 9:34
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179557%2fhow-do-i-make-linearmodelfit-flexible-to-number-of-parameters-using-fromletternu%23new-answer', 'question_page');
);
Post as a guest
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
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
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