NPavan
☆    

India,
2009-01-27 08:53
(5945 d 06:10 ago)

Posting: # 3133
Views: 5,900
 

 Quadratic Regression / SAS [Software]

Dear all,
Can anybody please give me SAS code for calculating quadratic regression equation y=ax2+bx+c using weighting factors 1/x and 1/x2.

--
Edit: Category changed. [Helmut]

Regards,
Pavan
d_labes
★★★

Berlin, Germany,
2009-01-27 09:26
(5945 d 05:37 ago)

@ NPavan
Posting: # 3134
Views: 5,056
 

 Proc Reg - The power to know

Dear Pavan,

have a very short look into the description of the SAS/Stat Proc REG and all your questions will be answered (RTFM in crude net-speak).

Then, if you have any specific question, come back.

Regards,

Detlew
NPavan
☆    

India,
2009-01-28 12:41
(5944 d 02:21 ago)

@ d_labes
Posting: # 3153
Views: 5,100
 

 Proc Reg

Dear D.Labes,

Thank you for your reply.

For the below data, I got the R2 values as follows
    X    |  Y
  50.020 | 0.012
  75.030 | 0.026
 100.040 | 0.035
 150.059 | 0.061
 175.069 | 0.073
 200.079 | 0.086
 300.119 | 0.134
 500.198 | 0.222
 750.296 | 0.364
1000.395 | 0.477
1100.435 | 0.618
1200.474 | 0.624


In Analyst Software
For Linear equation,
1) Using weighting index=1/x, R2 = 0.9956
2) Using weighting index=1/x2, R2 = 0.9875
3) For Quadratic equation using weighting index=1/x, R2= 0.9984

In SAS Analyst Using Simple Regression
For Linear equation,
1) Using weighting index =1/x, R2= 0.5069
2) Using weighting index =1/x2, R2 = 0.2734
3) For quadratic equation using weighting index 1/x, R2 = 0.7925

example for linear equation using weighting index 1/x2 SAS code is
*** Simple Regression ***;                                                   
 options pageno=1;                                                             
 proc reg data=Work.Sas;                                                       
    model Y = B;                                                           
run;                                                                         
quit;

Note: B=1/x2

Now my questions are,
1) Why my SAS R2 values are different compared to the Analyst R2 values?
2) Is there any mistake in my calculation?

Thanks in advance

--
Edit: Reformatted using BBCodes. Please don't use tabs in your posts; the result in different browsers is unpredicable. [Helmut]

Regards,
Pavan
d_labes
★★★

Berlin, Germany,
2009-01-28 14:53
(5944 d 00:09 ago)

@ NPavan
Posting: # 3154
Views: 5,083
 

 To know the power or ... is the question

Dear Pavan,

❝ *** Simple Regression ***;

❝ options pageno=1;

❝ proc reg data=Work.Sas;

❝ model Y = B;

❝ run; quit;

❝ note: B=1/x2


Now my questions are,

❝ 1) Why my SAS R2 values are different compared to the Analyst R2 values?

❝ 2) Is there any mistake in my calculation?


Answer to question 2: Not any, many!
Answer to question 1: see answer to question 2.

Hint: If you can analyze your data correctly within the 'ANALYST' application in SAS have a look at the code generated by it. It is shown below the analysis results. The emphasis lies on correctly! So use test data with known results.

To shorten the process of repeated Q&A here in this forum, which is not a SAS forum:
Steps to follow
1. Prepare a dataset with your y and x data.
2. Define an additional variable with the x value squared (f.i. x2=x*x;)
3. Define variables with your weights (f.i. w1=1/x; w2=1/(x*x);)
4. Code: *linear model
Proc reg data=yourdata;
  model y=x;
  weight w1; *if weighted by 1/x
run;quit;
*quadratic model
Proc reg data=yourdata;
  model y=x x2;
  weight w2; *if weighted by 1/x2
run;quit;


BTW: I strongly recommend that you attend a basic SAS course or buy a beginners SAS book! Ok, both are not cheap. So have a look at preceedings of SAS User conferences found here with many beginners lessions.

BTW2: For the other members of this forum interested in coding: See the elegant and intuitive way in doing polynomial regression in SAS. In another piece of this great software Proc GLM the same model is written
model y=x x*x; Sic!
It is a programming language of the 4th generation :-P !

Regards,

Detlew
NPavan
☆    

India,
2009-01-29 12:42
(5943 d 02:21 ago)

@ d_labes
Posting: # 3161
Views: 5,025
 

 Linear and Quadratic Regression

Dear D.Labes,

Thank you for your reply.

I have one more question,

In another data set the R2 values of both linear and quadratic are equal (ie 0.9954) in this situation,

How we can identify the best fit?

Is there any statistical test to decide which one is the best fit in all best fits of the linear and quadratic.

Regards,
Pavan
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2009-01-29 14:54
(5943 d 00:09 ago)

@ NPavan
Posting: # 3162
Views: 4,946
 

 Model selection

Dear Pavan!

❝ In another data set the R2 values of both linear and quadratic

❝ are equal (ie 0.9954) in this situation,


❝ How we can identify the best fit?


R2 (coefficient of determination) and R (coefficient of correlation) are ineffectual decision tools. To identify the best model first prepare a residual plot (x: calculated value, y: residual = calculated - measured):
  • If residuals are not evenly spread around zero (i.e., you see some kind of curve, or a trend) your model might be wrong -> add or remove terms.
  • If residuals look like a funnel, the assumption of homoscedasticity (independence of variance from the regressor variable) is not fullfilled. Your data are heteroscedastic -> try another weighting scheme.
See one of my presentations (slides 29-32). In the linear fit (w=1/x) we get a curve of residuals → going to quadratic, residuals are spread around zero – but there's still massive hetero­sce­das­ticity → final model: quadratic, w=1/x2.

❝ Is there any statistical test to decide which one is the best fit in all

❝ best fits of the linear and quadratic.


In my example you see that correlation is unsuitable; 0.9995 (w=1/x) seems to be better than 0.9994 (w=1/x2). Decision should be based on residuals and back-calculated x-values. The better model may be chosen based on the minimum AIC (Akaike's Information Criterion) which comes up with 149.5 for w=1/x and with 109.9 for w=1/x2. Another possibility would be an F-test.

Remember: According to FDA's guideline you have to justify the chosen model during validation. You may remove calibration points (during validation as well as in the study) only as long as the model will not change.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
NPavan
☆    

India,
2009-01-30 13:14
(5942 d 01:49 ago)

@ Helmut
Posting: # 3166
Views: 4,834
 

 Model selection

Dear HS,
Thank you for your reply.

Regards,
Pavan
UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,673 registered users;
213 visitors (0 registered, 213 guests [including 7 identified bots]).
Forum time: 16:03 CEST (Europe/Vienna)

Young man, in mathematics you don’t understand things.
You just get used to them.    John von Neumann

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5