问题类型 - 方程式
简述
方程式问题会根据其他答案计算出一个值,并将其与反馈一起保存。参与者不需要回答该问题:他们会看到计算结果,如果您隐藏该问题,则什么都看不到。您可以用它来计算总数、分数、根据出生年份得出的年龄、定制报告,或任何您希望保存在数据中而无需日后再计算的值。方程式可以使用 ExpressionScript 支持的任何语法。如果您处理的是数值,请确保使用问题设置仅限数字,详见下文。
下面的示例根据两个数字输入问题计算体质指数(BMI):


示例: Limesurvey_survey_BMIsample.lss.zip.
添加方程式问题
在新编辑器中:
- 点击顶栏中的紫色 +。问题类型选择器将打开。
- 在数字下,点击方程式。该问题会出现在当前题组的末尾。请将其放在所使用答案的问题之后。
- 点击您的问题在这里,并在花括号中输入包含计算的文本,例如
{Q023 * 12},用于根据问题Q023中的月度答案计算年度值。
在经典编辑器中:在结构选项卡中,点击添加问题。点击编号:旁边的问题类型按钮,在掩码问题组中选择方程式。输入编码和包含计算的问题文本,然后点击保存。
图中:1 为多数字输入问题的答案,2 为文本是 Total hours per week: {sum(Q024_SQ001, Q024_SQ002, Q024_SQ003)} 的方程式问题。总数会在参与者输入时实时更新。
编辑方程式问题
使用专用设置
设置方程式的最佳方式是使用专用设置方程式。在新编辑器中,它位于问题设置的简单视图中,以及高级设置 ⇒ 逻辑下。在经典编辑器中,它位于逻辑部分。这样所有语言都会使用同一个方程式,并且不会混入 HTML。您可以向参与者显示完整的句子,但只保存您需要的值:例如,在方程式中填入 {weightkg/(tall*tall/100/100)},并将“Your BMI is {self.NAOK}”作为问题文本显示。
请像在问题文本中一样,将表达式写在花括号中。
使用问题文本
如果没有设置方程式,则问题文本即为方程式:文本会被计算,并按参与者看到的样子保存。若只想保存数字,请在问题文本中只写计算式,例如 {sum(Q024_SQ001, Q024_SQ002, Q024_SQ003)},并使用始终隐藏本题隐藏该问题。
在经典编辑器中,您可以在 HTML 编辑器或其 HTML 源代码(源代码按钮)中编辑问题文本:
- 使用所见即所得(HTML/WYSIWYG)编辑器:

- 从HTML 源代码:

如果您希望在反馈中记录纯文本或纯数值,请编辑源代码。在源代码中,您可以删除会与值一起保存的任何 HTML 代码。点击确定关闭源代码窗口,然后点击保存保存该问题。

答案如何保存
方程式问题与其他答案一样,将其结果保存在其问题代码下:
- 设置了方程式时,保存的是该方程式的结果。
- 未设置时,保存的是参与者所看到的问题文本,其中包含计算出的值。例如文本为
Total hours per week: {sum(...)}时,保存的值为“Total hours per week: 36”。
即使使用始终隐藏本题隐藏了该问题,该值仍然会被计算并保存。
重要的设置
- 方程式:要保存的计算,见上文。
- 始终隐藏本题(显示):对参与者隐藏该问题。该值仍会被计算并保存。
- 仅限数字(其它):将结果保存为数字,以便您对其进行计算并在条件中进行比较。
- SPSS 导出尺度类型(其它):告知 SPSS 所保存的值是名义、顺序还是尺度类型。
所有设置的说明见下文。
常规选项
Mandatory
Description
This option allows the survey administrators to request their respondents to answer certain survey questions. If the mandatory questions are not answered, the respondents will not be able to proceed further. If you have a question with multiple subquestions, and you require only certain subquestions to be answered, use the minimum answer attribute located under the Logic tab.
Available options
- On - Question must be answered before the participant can proceed to the next page - the answer option 'No answer' is never shown.
- Soft - If the question is not answered, a warning is shown when trying to proceed to the next page - however, the participant can choose to ignore the warning and proceed. As with On, the answer option 'No answer' is not shown.
- Off (default) - Question can be left unanswered
Condition
Description
If the result value of the condition is "1" or "true", the question is "relevant" in the survey context, i.e. it is shown to the survey participant. If not, the question is hidden. Any survey question allows you to specify a relevance equation. This function is the successor of conditions and supports much more complex conditional logic.
Syntax Highlighting
Whenever you save the condition, it is evaluated and syntax-highlighted. Any errors will be color coded so that you can quickly detect and fix them.
Valid values
- Any condition that makes use of the ExpressionScript syntax, without surrounding curly braces.
Examples
Here are good examples of syntax highlighting.
显示
Description
If enabled, the question will always be hidden - it will not be displayed to the survey participants. This function can be used in the following scenarios:
- If you wish to prefill a question with a URL and you want not to have it displayed on the screen. This overrides any conditions used within the survey because the respective question will not even be embedded on the page.
- If you wish to store or calculate a value on the fly via the ExpressionScript - Presentation.
Available options
- On
- Off (default)
CSS class (css_class)
Description
If you want to add special CSS classes to certain questions, you can enter the CSS class name(s) in this box. Make sure you leave an empty space between different class names.
Valid values
- Any text string with a space between different CSS class names.
Relevance help for printable survey (printable_survey_relevance_help)
Description
If you wish to print a survey, you can also print the relevance equations for each question. But, if you wish to offer instead an explanation rather than the expression on the printed form, fill in this box with the text explanation for the relevance equation.
Valid values
- Any text and/or numbers you wish to be displayed on the printable form.
逻辑
Equation (equation)
Description
The result of the expression you type here will be stored in the response table and NOT the result(s) of the expressions typed in the question textbox. For example, you may want to display several expressions in the question textbox to display the respondents some statistics about herself. However, if you wish to store something different at the same time, then type the desired expression in this field.
This equation is used for all language.
Valid values
- Any text. The ExpressionScript syntax can also be used (with surrounding curly braces).
其他
Insert page break in printable view (page_break)
Description
This attribute is only active when you actually print a survey from the Printable View. It forces a page break before the question.
Available options
- On
- Off (default)
SPSS export scale type (scale_export)
Description
This is used for SPSS export only. This attribute overrides the default scale guessed by SPSS. To learn what the different measurement scales do, please read the related SPSS documentation.
Available options
- Default (default)
- Nominal
- Ordinal
- Scale
Numbers only (numbers_only)
Description
If you enable this option, the participant can only enter numbers in the text box(es).
For the equation question types, this setting indicates that the result could only be a number, not a string. This will guarantee proper calculations/conversions in follow-up equations regarding the decimal mark.
Behavior by question type
- Default: If the subject enters a value that is not a number, that value is immediately cleared from the text box so that the subject can enter an appropriate value.
- Array (Texts): If the numbers only option is disabled, the "Show totals for" and "Show grand total" options will be overruled, while the total text boxes will not be displayed.
- Equation: Enabling this option will force the equation results to be converted to a numeric value. If the equation result is not a number (and not blank), the equation will return NaN, being saved as an empty string in the response table.
Available options
- On
- Off (default)
统计
Show in public statistics (public_statistics)
Description
This attribute allows the survey administrator to chose if a particular question results should be displayed to the survey participants after they submitted the survey.
The default setting for each question is 'Off' (=Do not show the question statistics to the respondents). You have to enable this for every single question if you want to show the survey statistics of that (those) particular question(s) to the survey participants after the survey submission.
Available options
- On
- Off (default)
Display chart (display_chart)
Description
This attribute allows the survey administrator to choose if a chart that contains the question results should be displayed to the survey participants after they filled out the survey.
- public statistics survey setting from the presentation & navigation settings
- show graphs survey setting from the presentation & navigation settings
- public statistics question attribute, and
- display chart question attribute.
Available options
- On
- Off (default)
Chart type (chart_type)
Description
This attribute allows the survey administrator to choose which type of chart will be displayed to the respondent once he/she finished filling out the survey.
Available options
- Bar chart
- Pie chart
- Radar
- Line
- PolarArea
- Doughnut
常见问题
在哪里可以找到计算中需要的代码?
在新编辑器中,点击右上角的...,并在查看下打开Question codes。在经典编辑器中,代码显示在问题摘要和子问题选项卡中。请参阅重新生成问题编码。
可以在条件中使用方程式的结果吗?
可以,前提是所保存的值是数字:使用方程式设置,或使用只包含计算式的问题文本,并启用仅限数字。然后像使用其他答案一样使用其代码,例如 Q025 > 40。