[R] Sapply for descriptive statistics
I try to calculate descriptive statistics for one of the variables in the data frame, however command sapply calculates these statistics for every value of the variable separately. How to make it calculate range (as well as other statistics) for all column? Here are commands and results: > as1$trust [1] 5.957510 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721 7.017946 5.294411 [10] 7.296844 6.479167 5.009000 7.149073 5.932667 5.991000 5.327137 5.453230 5.650350 [19] 5.295608 5.518337 4.875000 6.637000 5.891014 6.726055 10.695650 5.490983 7.290476 [28] 5.728543 4.103689 8.421315 > des.trust <- sapply(as1$trust, range, na.rm=TRUE) > des.trust [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10] [1,] 5.95751 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721 7.017946 5.294411 7.296844 [2,] 5.95751 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721 7.017946 5.294411 7.296844 [,11] [,12][,13][,14] [,15][,16] [,17] [,18] [,19][,20] [,21] [1,] 6.479167 5.009 7.149073 5.932667 5.991 5.327137 5.45323 5.65035 5.295608 5.518337 4.875 [2,] 6.479167 5.009 7.149073 5.932667 5.991 5.327137 5.45323 5.65035 5.295608 5.518337 4.875 [,22][,23][,24][,25][,26][,27][,28] [,29][,30] [1,] 6.637 5.891014 6.726055 10.69565 5.490983 7.290476 5.728543 4.103689 8.421315 [2,] 6.637 5.891014 6.726055 10.69565 5.490983 7.290476 5.728543 4.103689 8.421315 tomii [[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.
[R] Effects - plot the marginal effect
Hello, I try to plot the marginal effect by using package "effects" (example of the graph i want to get is in the attached picture). All variables are continuous. Here is regression function, results and error effect function gives: > mreg01 = lm(a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres * > a90$proximity1), data=a90)> summary(mreg01) Call: lm(formula = a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres * a90$proximity1), data = a90) Residuals: Min 1Q Median 3Q Max -2.3173 -1.3349 -0.5713 0.8938 8.1084 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.2273 0.3090 13.683 < 2e-16 *** a90$enpres 0.4225 0.2319 1.822 0.072250 . a90$proximity1 -3.8797 1.0984 -3.532 0.000696 *** a90$enpres:a90$proximity1 0.8953 0.4101 2.183 0.032025 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.029 on 78 degrees of freedom Multiple R-squared: 0.2128, Adjusted R-squared: 0.1826 F-statistic: 7.031 on 3 and 78 DF, p-value: 0.0003029 > plot(effect(a90$enpres:a90$proximity1, mreg01))Warning messages:1: In > a90$enpres:a90$proximity1 : numerical expression has 82 elements: only the first used2: In a90$enpres:a90$proximity1 : numerical expression has 82 elements: only the first used3: In analyze.model(term, mod, xlevels, default.levels) : 0 does not appear in the modelError in plot(effect(a90$enpres:a90$proximity1, mreg01)) : error in evaluating the argument 'x' in selecting a method for function 'plot' > Thanks in advance. Tomas <>__ 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.
Re: [R] Effects - plot the marginal effect
Thank you for your response, but these changes doesn't seem to change anything, outcomes of effect command is still the same - error. Tomas On Fri, Apr 1, 2011 at 5:03 AM, John Fox wrote: > Dear Tomas, > > Write the model as > > mreg01 = lm(enep1 ~ enpres * proximity1), data=a90) > > That is, it's not necessary to index a90 as a list since it's given as the > data argument to lm, and doing so confuses the effect() function. Also, > enpres*proximity1 will include both the enpres:proximity1 interaction and > enpres + proximity1, which are marginal to the interaction. > > Next, you must quote the name of the term for which you want to compute > effects, thus "enpres:proximity1" in the call to effect(). > > Finally, effect() doesn't compute what are usually termed marginal effects. > If you want more information about what it does, see the references given in > ?effect. > > I hope this helps, > John > > > John Fox > Sen. William McMaster Prof. of Social Statistics > Department of Sociology > McMaster University > Hamilton, Ontario, Canada > http://socserv.mcmaster.ca/jfox/ > > On Thu, 31 Mar 2011 22:09:32 +0200 > Tomii wrote: > > Hello, > > > > I try to plot the marginal effect by using package "effects" (example of > the > > graph i want to get is in the attached picture). > > All variables are continuous. > > > > Here is regression function, results and error effect function gives: > > > > > mreg01 = lm(a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres * > a90$proximity1), data=a90)> summary(mreg01) > > Call: > > lm(formula = a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres * > > a90$proximity1), data = a90) > > > > Residuals: > > Min 1Q Median 3Q Max > > -2.3173 -1.3349 -0.5713 0.8938 8.1084 > > > > Coefficients: > > Estimate Std. Error t value Pr(>|t|) > > (Intercept) 4.2273 0.3090 13.683 < 2e-16 *** > > a90$enpres 0.4225 0.2319 1.822 0.072250 . > > a90$proximity1 -3.8797 1.0984 -3.532 0.000696 *** > > a90$enpres:a90$proximity1 0.8953 0.4101 2.183 0.032025 * > > --- > > Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 > > â â 1 > > > > Residual standard error: 2.029 on 78 degrees of freedom > > Multiple R-squared: 0.2128, Adjusted R-squared: 0.1826 > > F-statistic: 7.031 on 3 and 78 DF, p-value: 0.0003029 > > > plot(effect(a90$enpres:a90$proximity1, mreg01))Warning messages:1: In > a90$enpres:a90$proximity1 : > > numerical expression has 82 elements: only the first used2: In > > a90$enpres:a90$proximity1 : > > numerical expression has 82 elements: only the first used3: In > > analyze.model(term, mod, xlevels, default.levels) : > > 0 does not appear in the modelError in > > plot(effect(a90$enpres:a90$proximity1, mreg01)) : > > error in evaluating the argument 'x' in selecting a method for function > 'plot' > > > > > > > > > Thanks in advance. > > Tomas > > > > [[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.