Hi R community

I have a question. I'll explain my situation. I have to build a climate model 
to obtain monthly and annual temperature from 2004 to 2008 from a specif area 
in Almeria (Spain). To build this climate model, I will use Multiple 
regression. My dependant variable will be monthly and annual temperature and 
independant variables will be Latitute, Longitude and Altitude and I will work 
with climate data from 10 climate stations distributed in my area of interest.  
I have to fit the climate model from the data to get temperature for each 
month. And I need to use p-value and r-squared adjusted from the model to 
obtain the best fit. I'll put an example. My climate data will be:

 V1 V2 V3 V4  V5
1  1 18  3  6 187
2  2 21  6  8  68
3  3 23  9  5  42
4  4 19  8  2 194
5  5 17  3  2 225

(V1 - climate station, V2 - temperature, V3 - Latitude, V4 - Longitude, V5 - 
Altitude)

I fit the model to the data

 fit(V2~V3+V4+V5, data=clima)

And I get 

Call:
lm(formula = V2 ~ V3 + V4 + V5, data = clima)

Residuals:
       1        2        3        4        5 
 0.24684 -0.25200  0.17487 -0.05865 -0.11107 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)  
(Intercept) 22.103408   2.526638   8.748   0.0725 .
V3           0.236477   0.152067   1.555   0.3638  
V4          -0.073973   0.169716  -0.436   0.7383  
V5          -0.024684   0.006951  -3.551   0.1748  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.4133 on 1 degrees of freedom
Multiple R-squared: 0.9926,     Adjusted R-squared: 0.9706 
F-statistic: 44.95 on 3 and 1 DF,  p-value: 0.1091 

P- value for this model is 0.1091

However, I see that variable V4 has a really high p-value, so if I take it out, 
my model will have a better p-value. So:

fit2<-lm(V2~V4+V5)

Call:
lm(formula = V2 ~ V4 + V5, data = clima)

Residuals:
       1        2        3        4        5 
 0.28356 -0.21880  0.05952  0.40918 -0.53346 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)   
(Intercept) 25.764478   1.199212  21.485  0.00216 **
V4          -0.278286   0.140452  -1.981  0.18606   
V5          -0.034109   0.004451  -7.664  0.01660 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.5403 on 2 degrees of freedom
Multiple R-squared: 0.9748,     Adjusted R-squared: 0.9497 
F-statistic: 38.74 on 2 and 2 DF,  p-value: 0.02516 

My new p value for the model is lower, and better. So, this is what I have to 
do, I have to import climate data, and build the climate model using those 
independant variables that give me the best p-value for the model, and I have 
to do it automatic (since this example I did it manual). So, my question after 
all this long explanation. Is there a package u order I can download to apply 
selection of independent variables using as criteria p-value and adjusted 
R-squered, or on the contrary, I have to build what I need by myself. I guess I 
can build it by myself but it will take me a while but I would like to know if 
there is some package to help to do it faster. Well, thanks in advance.

Lucas
                                          
_________________________________________________________________
Nuevo Windows Live, un mundo lleno de posibilidades. Descúbrelo.
http://www.microsoft.com/windows/windowslive/default.aspx
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to