Skip to content

Adjusting length of series

6 messages · David Winsemius, Lekgatlhamang, lexi Setlhare, arun

#
On Jul 2, 2012, at 5:13 AM, Lekgatlhamang, lexi Setlhare wrote:

            
Well, your initial question (why the $ referencing did not work) is  
now answered. This is not a dataframe but rather a 'ts' classed object  
and there is no `$` method for such objects. They are really matrices  
with some extra attributes.

 > ydata$BoBCL1
Error in ydata$BoBCL1 : $ operator is invalid for atomic vectors

As I understood it you were able to get useful analyses using the  
formula methods for lm on these objects, but were just having  
difficulty with the "$" operator. So the answer is ..... don't do that.
#
Hello,

The class of your data is not dataframe.
Suppose I call your data as ydat1

str(ydat1)

?mts [1:24, 1:7] 68.1 -34.8 90.4 54.6 -172.3 ...
?- attr(*, "dimnames")=List of 2
? ..$ : NULL
? ..$ : chr [1:7] "DCred1" "DCred2" "DCred3" "DBoBC2" ...
?- attr(*, "tsp")= num [1:3] 2001 2003 12
?- attr(*, "class")= chr [1:2] "mts" "ts"

ydat2<-data.frame(ydat1)

str(ydat2)
'data.frame':??? 24 obs. of? 7 variables:
?$ DCred1: num? 68.1 -34.8 90.4 54.6 -172.3 ...
?$ DCred2: num? NA -102.9 125.2 -35.8 -226.9 ...
?$ DCred3: num? NA NA 228 -161 -191 ...
?$ DBoBC2: num? NA -164.5 17.1 96 680.2 ...
?$ DBoBC3: num? NA NA 181.5 78.9 584.3 ...
?$ CredL1: num? 4937 5005 4970 5061 5115 ...
?$ BoBCL1: num? 4188 4296 4240 4201 4258 ...

#Since you wanted only to do lm for these columns, I guess it doesn't really matter whether you have month and year in the dataset.
?#With NAs
?regCred<-lm(DCred1~DCred2+DCred3+DBoBC2+DBoBC3+CredL1+BoBCL1,data=ydat2)
Call:
lm(formula = DCred1 ~ DCred2 + DCred3 + DBoBC2 + DBoBC3 + CredL1 + 
??? BoBCL1, data = ydat2)

Residuals:
??????? Min????????? 1Q????? Median????????? 3Q???????? Max 
-124.988463? -33.133975??? 7.971083?? 23.607953?? 76.813601 

Coefficients:
???????????????? Estimate??? Std. Error? t value?? Pr(>|t|)??? 
(Intercept) -538.61375718? 205.91179535 -2.61575?? 0.020344 *? 
DCred2???????? 0.96401908??? 0.15623660? 6.17025 2.4337e-05 ***
DCred3??????? -0.25720355??? 0.08983607 -2.86303?? 0.012524 *? 
DBoBC2??????? -0.11222347??? 0.07828182 -1.43358?? 0.173646??? 
DBoBC3???????? 0.04564621??? 0.03825169? 1.19331?? 0.252578??? 
CredL1???????? 0.18499925??? 0.06565456? 2.81777?? 0.013693 *? 
BoBCL1??????? -0.07682710??? 0.03406916 -2.25503?? 0.040666 *? 
---
Signif. codes:? 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 

Residual standard error: 54.44479 on 14 degrees of freedom
? (3 observations deleted due to missingness)
Multiple R-squared: 0.9324472,??? Adjusted R-squared: 0.903496 
F-statistic: 32.20757 on 6 and 14 DF,? p-value: 2.046024e-07 
Without NAs
Call:
lm(formula = DCred1 ~ DCred2 + DCred3 + DBoBC2 + DBoBC3 + CredL1 + 
??? BoBCL1, data = ydat3)

Residuals:
??????? Min????????? 1Q????? Median????????? 3Q???????? Max 
-124.988463? -33.133975??? 7.971083?? 23.607953?? 76.813601 

Coefficients:
???????????????? Estimate??? Std. Error? t value?? Pr(>|t|)??? 
(Intercept) -538.61375718? 205.91179535 -2.61575?? 0.020344 *? 
DCred2???????? 0.96401908??? 0.15623660? 6.17025 2.4337e-05 ***
DCred3??????? -0.25720355??? 0.08983607 -2.86303?? 0.012524 *? 
DBoBC2??????? -0.11222347??? 0.07828182 -1.43358?? 0.173646??? 
DBoBC3???????? 0.04564621??? 0.03825169? 1.19331?? 0.252578??? 
CredL1???????? 0.18499925??? 0.06565456? 2.81777?? 0.013693 *? 
BoBCL1??????? -0.07682710??? 0.03406916 -2.25503?? 0.040666 *? 
---
Signif. codes:? 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 

Residual standard error: 54.44479 on 14 degrees of freedom
Multiple R-squared: 0.9324472,??? Adjusted R-squared: 0.903496 
F-statistic: 32.20757 on 6 and 14 DF,? p-value: 2.046024e-

#Same result
Not sure what you meant by ("This is good, but couldn't I code the process for my 15 variable model?")


A.K.
#
Hi,

One more thing,
ydat1: original dataset


?ydat2<-data.frame(ydat1)

#Not sure ,how you did this step on original data because::
dframe<- data.frame(Dcre1=DCred1[1:21],Dcre2=DCred2[1:21],Dcre3=DCred3[1:21],
?Dbobc2=DBoBC2[1:21],Dbobc3=DBoBC3[1:21],CredL=CredL1[1:21],BoBCL=BoBCL1[1:21])

I am getting errors for that step, when I used ydat1.


head(ydat1)
[1]?? 68.1? -34.8?? 90.4?? 54.6 -172.3?? 51.8


?head(ydat2)
? DCred1 DCred2 DCred3???? DBoBC2????? DBoBC3 CredL1?? BoBCL1
1?? 68.1???? NA???? NA???????? NA????????? NA 4937.0 4187.500
2? -34.8 -102.9???? NA -164.45784????????? NA 5005.1 4296.005
3?? 90.4? 125.2? 228.1?? 17.07935?? 181.53719 4970.3 4240.052
4?? 54.6? -35.8 -161.0?? 95.97679??? 78.89743 5060.7 4201.178
5 -172.3 -226.9 -191.1? 680.23817?? 584.26138 5115.3 4258.281
6?? 51.8? 224.1? 451.0 -491.34869 -1171.58686 4943.0 4995.623




#I analyzed [1:21] again in ydat2.

dframe<-data.frame(Dcre1=ydat2$DCred1[1:21],Dcre2=ydat2$DCred2[1:21],Dcre3=ydat2$DCred3[1:21],Dbobc2=ydat2$DBoBC2[1:21],Dbobc3=ydat2$DBoBC3[1:21],CredL=ydat2$CredL1[1:21],BoBCL=ydat2$BoBCL1[1:21])
But, the results are bit different than in my earlier post, because, here the NAs are still present in different rows.? So, the observations in those rows will be deleted while it is analyzed.

regCred<- lm(Dcre1~Dcre2+Dcre3+Dbobc2+Dbobc3+CredL+BoBCL, data=dframe)
Call:
lm(formula = Dcre1 ~ Dcre2 + Dcre3 + Dbobc2 + Dbobc3 + CredL + 
??? BoBCL, data = dframe)

Residuals:
???? Min?????? 1Q?? Median?????? 3Q????? Max 
-118.687? -25.568?? -5.334?? 35.035?? 69.992 

Coefficients:
????????????? Estimate Std. Error t value Pr(>|t|)??? 
(Intercept) -485.42427? 209.47952? -2.317 0.038958 *? 
Dcre2????????? 0.95097??? 0.18156?? 5.238 0.000209 ***
Dcre3???????? -0.28676??? 0.10787? -2.658 0.020852 *? 
Dbobc2??????? -0.09512??? 0.09334? -1.019 0.328278??? 
Dbobc3???????? 0.03199??? 0.04933?? 0.648 0.528936??? 
CredL????????? 0.14825??? 0.07193?? 2.061 0.061645 .? 
BoBCL???????? -0.04844??? 0.04333? -1.118 0.285540????

---
A.K.